Table Of Contents

Related Topics

Box Layout

Arrange widgets in a vertical or an horizontal box.

Example of a vertical layout:

layout = BoxLayout(orientation='vertical')
btn1 = Button(text='Hello')
btn2 = Button(text='World')
layout.add_widget(btn1)
layout.add_widget(btn2)

Example of a horizontal layout, with a border of 10 pixels between the layout and all the childrens, and the first button should be 70% of the layout, and the second should be 30%.

layout = BoxLayout(spacing=10)
btn1 = Button(text='Hello', size_hint=(.7, 1))
btn2 = Button(text='World', size_hint=(.3, 1))
layout.add_widget(btn1)
layout.add_widget(btn2)

Note

The size_hint represent the size available after substracting all the fixed size. For example, if you have 3 widgets (width is 200px, 50%, 50%), and if the layout have a width of 600px :

  • the first widget width will be 200px
  • the second widget width will be 300px
  • the third widget width will be 300px
class kivy.uix.boxlayout.BoxLayout(**kwargs)

Bases: kivy.uix.layout.Layout

Box layout class. See module documentation for more informations.

orientation

Orientation of the layout.

orientation is an OptionProperty, default to ‘horizontal’. Can take a value of ‘vertical’ or ‘horizontal’.

padding

Padding between widget box and children, in pixels.

padding is a NumericProperty, default to 0.

spacing

Spacing is the space between each children, in pixels.

spacing is a NumericProperty, default to 0.

update_minimum_size(*largs)

Calculates the minimum size of the layout.

In calculation, there must be a space for child widgets that have fixed size (size_hint == (None, None)). There must also be at least enough space for every child layout’s minimum size (cant be too small even if size_hint is set).