Reputation: 127
First of all, if they are some system differences, I work on Ubuntu 12.04, using current Kivy version. My problem is that i'm unable to set layout size.
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
class TestApp(App):
def build(self):
layout = BoxLayout(orientation='vertical', size=(200,200))
btn1 = Button(text='Hello', size=(50,50), size_hint=(None, None))
btn2 = Button(text='World', size=(50,50), size_hint=(None, None))
layout.add_widget(btn1)
layout.add_widget(btn2)
return layout
TestApp().run()
Any idea?
Upvotes: 5
Views: 16145
Reputation: 5949
Root widget will always be the size of the window, you can change your code to:
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.floatlayout import FloatLayout
class TestApp(App):
def build(self):
root = FloatLayout()
layout = BoxLayout(orientation='vertical', size=(200,200), size_hint=(None, None))
btn1 = Button(text='Hello', size=(50,50), size_hint=(None, None))
btn2 = Button(text='World', size=(50,50), size_hint=(None, None))
layout.add_widget(btn1)
layout.add_widget(btn2)
root.add_widget(layout)
return root
TestApp().run()
But using a boxlayout and use custom size to all children seems a little weird.
Upvotes: 8