Kivy: How to change window size?

Bakuriu picture Bakuriu · Dec 23, 2012 · Viewed 49.9k times · Source

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.

Answer

martin picture martin · May 19, 2015

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)