Table Of Contents
Layout¶
Layouts are used to calculate and assign widget positions.
The Layout
class itself cannot be used directly.
You should use one of the following layout classes:
- Anchor layout:
kivy.uix.anchorlayout.AnchorLayout
- Box layout:
kivy.uix.boxlayout.BoxLayout
- Float layout:
kivy.uix.floatlayout.FloatLayout
- Grid layout:
kivy.uix.gridlayout.GridLayout
- Page Layout:
kivy.uix.pagelayout.PageLayout
- Relative layout:
kivy.uix.relativelayout.RelativeLayout
- Scatter layout:
kivy.uix.scatterlayout.ScatterLayout
- Stack layout:
kivy.uix.stacklayout.StackLayout
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). The format is:
widget.size_hint = (width_percent, height_percent)
The percent is specified as a floating point number in the range 0-1. For example, 0.5 is 50%, 1 is 100%.
If you want a widget’s width to be half of the parent’s width and the height to be identical to the parent’s height, you would do:
widget.size_hint = (0.5, 1.0)
If you don’t want to use a size_hint for either the width or height, set the value to None. For example, to make a widget that is 250px wide and 30% of the parent’s height, do:
widget.size_hint = (None, 0.3)
widget.width = 250
Being Kivy properties
, these can also be set via
constructor arguments:
widget = Widget(size_hint=(None, 0.3), width=250)
Changed in version 1.4.1: The reposition_child internal method (made public by mistake) has been removed.
-
class
kivy.uix.layout.
Layout
(**kwargs)[source]¶ Bases:
kivy.uix.widget.Widget
Layout interface class, used to implement every layout. See module documentation for more information.