Disable fullscreen kivymd - python

I have been working on some projects with kivy for a while, some of them requiring fullscreen, but now I want to learn kivymd. The problem is that my kivymd app opens in fullscreen, how can I change that from the code? Also, how can I change the default window size of the application?

Set the window size BEFORE importing MD modules and BEFORE importing the kivy.core.window.Window module!
from kivy.config import Config
Config.set('graphics', 'width', '200')
Config.set('graphics', 'height', '200')
[impots MD modules]
[impots kivy.core.window.Window modules]

It is simple resizing the windows but note one thing while packing this for android apk you should remove these lines:
from kivy.core.window import Window
Window.size =[x ,y]
The x and y variables is upto your choice

Add this lines at the top your code. change the values to adjust the size of your window to your desired size.
from kivy.core.window import Window
Window.size = (370, 700)

Related

How to fix KIVY default window on app appearing thin on launch... almost without width?

All of the projects I opened on Kivy open up with a really long but thin window... I have no idea why or how I this happened. Could someone please help me fix this?
Here is a screen shot! Thank you so much
-https://drive.google.com/file/d/17PeHfFJBkMPI-eW4PbO8qzwG2W2IM1hn/view?usp=sharing
You may set the width and height before opening your window:
import kivy
kivy.require('1.11.0')
from kivy.config import Config
# Ensure window is going to be 800x400
Config.set('graphics', 'width', '800')
Config.set('graphics', 'height', '400')
Alternatively, you can set the window size after creating it with its size attribute, which is a (width, height) tuple:
from kivy.core.window import Window
Window.size = (800, 400)
You can find more configuration options here: https://kivy.org/doc/stable/api-kivy.config.html

Can't close Kivy app or avoid fullscreen

I am new to Kivy and trying to find my way around. Whenever I create and run an app, it displays as a full-screen that I am unable to close without disconnecting the power (which I know is not ideal, but that's exactly why I am desperate to fix it!).
Shortcuts that are suggested to work (Esc, Ctrl+C, Ctrl+Alt+break) don't. I have attempted changing the config settings at the beginning of the script as follows:
from kivy.config import Config
Config.set('graphics', 'fullscreen', 0)
Config.write()
I've also tried variations on the theme - 0 as a string, 1 as both an integer and string (and trying to provide a width and height for the window) but with no perceivable change. Even if this did work, it would not be the ideal fix given that I would probably want to be able to run things full-screen in the end!
Given that each time I've tried changing something I've had to restart the pi by disconnecting the power, playing around has been quite time-consuming!
Does anybody have any suggestions about how I should proceed?
I'm currently using:
Raspberry Pi 2 Model B connected to normal TV (many people having problems have been using a touchscreen, but that is not true for me)
Raspbian Jessie, Linux 8
Python 2.7
I'm afraid I don't know how to check details about the Kivy module I have downloaded.
I'm very new to this, so apologies if I don't manage to provide all of the relevant information.
Full code I am trying to run (excluding the above config changes):
import kivy
kivy.require('1.9.2') #may be part of the problem - not 100% sure this is correct
from kivy.app import App
from kivy.uix.label import Label
class MyApp(App):
def build(self):
return Label(text='Hello world')
if __name__ == '__main__':
MyApp().run()
As a temporary workaround you could just do :
def build(self):
button = Button(text = 'Exit', size_hint = (.1, .05),
pos_hint = {'x':0, 'y':0})
button.bind(on_press = self.on_quit)
self.layout = FloatLayout()
self.layout.add_widget(button)
return self.layout
def on_quit(self):
exit()
Which would provide you with an exit button. For your fullscreen problem it's weird, can you provide some more code ?
EDIT:
Can you try this ? :
from kivy.config import Config
Config.set('graphics', 'borderless', 0)
Config.write()
To work around this issue, you can change the full screen to fake so kivy can exit on Ctrl+C.
from kivy.config import Config
Config.set('graphics', 'fullscreen', 'fake')
Config.write()
Also, try to run the code in command line prompt. Avoid raspberry pi's desktop environment while running kivy apps. This will free up pi's memory for running kivy.

Force Window Size Kivy

I don't find how to force the window size with the kivy language. (ex: 800x600p)
Can you help me ?
Thanks for reading.
PITO2901
The KV language does not have the ability to configure window settings, but it can be done easily in your 'main.py' file by using the Config object from kivy.config. Just make sure to put any configuration you do before your other imports. Otherwise, they won't work.
# configuration
from kivy.config import Config
Config.set('graphics', 'width', 800)
Config.set('graphics', 'height', 600)
# other imports
from kivy.app import App
from kivy.uix.widget import Widget
...
Set kivy.core.window.Window.size to (800, 600).
You can't set it directly in kv, but you could bind it to a button or similar. You would also need to import the Window to kv, using the #:import statement explained in the doc.

Issue setting Kivy to fullscreen

I'm trying to write an application that runs kivy at full screen. But these are my issues:
1) When I run the command:
#Config.set('graphics', 'fullscreen', 1)
Then kivy appears to go full time, but the window has a lot of black spaces around the background image. Even if I elongate the image, kivy just cuts the image when showing it.
2) When I run this command to set the window size to the size of my screen:
Config.set('graphics', 'width', '1366')
Config.set('graphics', 'height', '768')
This way actually gives me a better result than full screen, but kivy returns a height parameter of only 715 instead of the 768, which is the value I told kivy to use (as you can see in the Config.set() function above).
My screen resolution is 1366x768
How can I solve this issue and make my kivy app go real full screen?
Thank you very much
Had a similar problem. Using the 'auto' option got rid of the bands for me.
Window.fullscreen = 'auto'
Quote from Kivy Configuration Object documentation: "If set to auto, your current display’s resolution will be used instead. This is most likely what you want."
Try
from kivy.core.window import Window
Window.fullscreen = True
Do this before you App.run() method, and it should switch to fullscreen mode.
Cheers
I managed to do it as follows:
from kivy.core.window import Window
Window.maximize()
I just want to complement:
from kivy.core.window import Window
Window.size = (1366, 768)
Window.fullscreen = True
this works for me:
Config.set('graphics', 'fullscreen', 'auto')
Answering lately For those who are still struggling to figure out how to have the true fullscreen. I have managed to get the rid of those black strip by adding Config.set('graphics','window_state'_'maximized' just after the fullscreen call. the whole code looks like
from kivy.config import Config
# ...
if __name__ == "__main__":
Config.set('graphics', 'fullscreen', 'auto')
Config.set('graphics', 'window_state', 'maximized')
Config.write()
YourApp().run()
This will work no matter what is your resolution.
from kivy.core.window import Window
Window.fullscreen = True
Window.maximize()

Kivy: How to change window size?

I'm starting to write a program using kivy, but I have some problems understand how it deals with sizes.
For example:
import kivy
kivy.require('1.5.1')
from kivy.app import App
from kivy.uix.button import Button
class MyApp(App):
def build(self): return Button(text='Some text')
MyApp().run()
The above program works, but it creates a huge window. Trying to set size=(100, 100) does not change anything. Setting size_hint=(None, None) will show a button with the correct size, but it is placed randomly inside a still huge window.
Trying to set the size of MyApp does not change anything too.
How do I create a window with the same size of the button?
It should be a simple enough task, but looking at the documentation and example I can't find anything about this.
There're currently two ways:
Before the window is created:
import kivy
kivy.require('1.9.0')
from kivy.config import Config
Config.set('graphics', 'width', '200')
Config.set('graphics', 'height', '200')
Dynamically after the Window was created:
from kivy.core.window import Window
Window.size = (300, 100)
Use this:
from kivy.core.window import Window
Window.size = (300, 100)
If you use
from kivy.config import Config
Config.set('graphics', 'width', '200')
Config.set('graphics', 'height', '200')
Config.write()
this will lead to loss of default screen size!
Default screen size is really useful.
I would comment on martin's answer, but I don't have the reputation. When setting the config file, be sure to "write" your changes:
from kivy.config import Config
Config.set('graphics', 'width', '200')
Config.set('graphics', 'height', '200')
Config.write()
It's exactly like committing info to a database, if you know anything about that.
Using Config.write() will set your changes to the default settings. If you accidentally run this and want to revert the changes, you can either run Config.write() again with the default values (therefore reverting your changes) or you can open up $HOME/.kivy/config.ini with a text editor and edit it.

Categories