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?
Python3. # base Class of your App inherits from the App class. # BoxLayout arranges children in a vertical or horizontal box.
Understanding the size_hint Property in Widget ¶ The size_hint is a tuple of values used by layouts to manage the sizes of their children. It indicates the size relative to the layout's size instead of an absolute size (in pixels/points/cm/etc).
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.
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