Reputation: 2078
I'm new to python and want to have a UI for my small app. I use kivy as the GUI framework. I'm wondering about the layout.
How can I organise my layout? I have tried embedding boxlayout inside gridlayout, but alway got messed in position.
Upvotes: 1
Views: 579
Reputation: 8747
You should just embed GridLayout
inside vertically oriented BoxLayout
and use size_hint
to select how much space should widgets take. For example size_hint: 1, 0.25
results with widget taking all available space horizontally and 1/4 of the available space vertically. Result:
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import BooleanProperty
from kivy.lang import Builder
Builder.load_string('''
<MyWidget>:
orientation: 'vertical'
Label:
size_hint: 1, 0.25
text: 'Label1'
GridLayout:
size_hint: 1, 0.25
cols: 2
Button
text: 'Button1'
Button
text: 'Button2'
Button
text: 'Button3'
Button
text: 'Button4'
Label:
size_hint: 1, 0.5
text: 'Label2'
''')
class MyWidget(BoxLayout):
pass
class MyApp(App):
def build(self):
return MyWidget()
if __name__ == '__main__':
MyApp().run()
Upvotes: 2