I follwed this stackoverflow question, but neither alternatives worked.
This is my code:
from kivy.app import App
from kivy.uix.label import Label
from kivy.core.window import Window
class MyApp(App):
def build(self):
return Label(text='text')
if __name__ == '__main__':
Window.size = (1366, 768)
MyApp().run()
Sometimes the size works, Kivy creates a screen with size 800x600
then changes it to 1366x768
. And sometimes Kivy creates a screen with size 800x600
then changes it to 1366x768
, but then back to 800x600
.
And if I change my code to:
from kivy.app import App
from kivy.uix.label import Label
from kivy.core.window import Window
from kivy.config import Config
Config.set('graphics', 'width', '200')
Config.set('graphics', 'height', '200')
class MyApp(App):
def build(self):
return Label(text='text')
if __name__ == '__main__':
MyApp().run()
With this code, nothing happens on my screen. I'm using Kivy v1.9.2-dev0
. What I should do to fix it?
#import everything you want from kivy. core. window import Window #You must import this Window. size = (600, 600) #Set it to a tuple with the (width, height) in Pixels #(800, 600) is the default #Your usual kivy code....
Kivy Config File We must import the Config class to set the window size. Then we have to configure the window's width and height. To accomplish this, we use the Config object's set method.
Either through the config http://kivy.org/docs/api-kivy.config.html or through the cmd line args (try `python kivyapp.py --help` to see the available options). For android and ios the app should be fullscreen anyways so getting the window. size should give you the screen resolution.
Kivy is a platform independent as it can be run on Android, IOS, linux and Windows etc. Kivy provides you the functionality to write the code for once and run it on different platforms. It is basically used to develop the Android application, but it Does not mean that it can not be used on Desktops applications.
Put the Config settings before all the other imports - it's too late after importing Window, as the config has already been accessed to determine its initial size and your new settings are ignored.
Make your window non-resizable
from kivy.config import Config
Config.set('graphics','resizable',0)
set the window size
from kivy.core.window import Window
Window.size = (600, 500)
see example at https://kivyapps.wordpress.com/video-streaming-using-kivy-and-python/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With