7

Is there any way to keep the window size for Kivy programs fixed? Fixed in the sense its window size cannot be increased or decreased. For example, I want a Kivy program whose window size is 500x500 and the end user cannot either change the window size or turn it into fullscreen. I tried setting the height, width, minimum_height and minimum_width all with same values and still I can change window size and fullscreen it.

5 Answers 5

18

There is a way to configure the app to disable resizing

from kivy.config import Config
Config.set('graphics', 'resizable', False)

Also, the same way you can set the default width-height of the window.
Keep something in mind. Doing it like that in the beginning of your app, it will keep the settings only for that app. However, if you then run a Config.write(), you'll save the settings in a configuration file.

Config.set should be used before importing any other Kivy modules. Ideally, this means setting them right at the start of your main.py script. Alternatively, you can save these settings permanently using Config.set then Config.write. In this case, you will need to restart the app for the changes to take effect. Note that this approach will effect all Kivy apps system wide.

Read this wiki article for more info.

2
  • Oh damn silly me. I totally missed that part of wiki. :\ But could you explain what you meant by if I Config.set in the beginning, it'll keep settings only for that app? Commented May 11, 2016 at 14:02
  • @ParthibBiswas If you don't do the Config.write() call, it won't apply the settings to all apps, just for this one, which is probably what you want.
    – illright
    Commented May 11, 2016 at 14:06
4

There are actually a bunch of ways you can do this, that said many of them are dependent on how you're writing your code and since you've not given us an example I can only show you basic examples...

Say for instance your'e not using the kivy deign language and you're doing your project in straight python you could for instance setup a Root widget in the following way

Root = Widget(size = (500,500))

You could also avoid that and simply do for instance

Window.size = (500, 500)

Now if you're using the kv design language it's just eas easy except you'd be setting the size of your canvas, Rectangles etc.. inside the .kv file.

And as mentioned by @Leva7 you could also use for instance

from kivy.config import Config
Config.set('graphics', 'resizable', '0') #0 being off 1 being on as in true/false
Config.set('graphics', 'width', '500')
Config.set('graphics', 'height', '500')

Note that the above (Ie, Config.set()) should be placed at the top of the source code near the import section!

2

You can give like this on kivy-1.10.0+

import kivy
from kivy.app import App
from kivy.core.window import Window
from kivy.config import Config
kivy.config.Config.set('graphics','resizable', False)



class MyApp(App):
    def build(self):
        Window.size = (1280,720)
MyApp().run()
0

The above stated configurations dont work for the RPi by default.

Window.size(500,500)

takes no effect. If someone needs to disable the fullscreen and want to have full control over the screen size on his RPi:

disable kivy fullscreen

Steps to do:

sudo raspi-config 

Advanced Options ->
GL Driver ->
G1 GL (Full KMS)->
OK ->
Reboot

Tested on RPi 3B Stretch with Python3.5

0

A Non-attractive way to fix the size is by adding an event listener.

from kivy.core.window import Window

_fixed_size = (425, 700) #desired fix size

def reSize(*args):
   Window.size = _fixed_size
   return True
Window.bind(on_resize = reSize)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.