Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting kivy window size not working

Tags:

python

kivy

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?

like image 211
Carlos Porta Avatar asked May 03 '16 05:05

Carlos Porta


People also ask

How do I change the window size in kivy?

#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....

How can I get window width in kivy?

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.

How do I find the screen size of my kivy?

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.

Is kivy good for Windows?

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.


2 Answers

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.

like image 157
inclement Avatar answered Nov 11 '22 01:11

inclement


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/

like image 28
Atul Avatar answered Nov 11 '22 01:11

Atul