In this video I’ll explain the Box Layout for Kivy and Python.
Kivy comes with several layout options to choose from. In this video we’ll look at Box Layout, which is basically just a stacked layout that’s oriented horizontally or vertically.
Or to put it another way, Box Layout arranges children in a vertical or horizontal box.
We’ll also look at sizing things in Box Layout, and positioning things as well.
Python Code: box.py
(Github Code)
from kivy.app import App from kivy.uix.widget import Widget from kivy.properties import ObjectProperty from kivy.lang import Builder # Designate Our .kv design file Builder.load_file('box.kv') class MyLayout(Widget): pass class AwesomeApp(App): def build(self): return MyLayout() if __name__ == '__main__': AwesomeApp().run()
Kivy Design Code: box.kv
(Github Code)
<MyLayout> BoxLayout: orientation: "vertical" size: root.width, root.height padding: 50 spacing: 20 Button: text: "Hello World!" Button: text: "Goodbye World!" Button: text: "I'm Hungry!" pos_hint: {'center_x': 0.5} size_hint: (1,.3) #width: 200 #height: 50
Add comment