Using AnchorLayout
AnchorLayout aligns the children to a border or center. In this recipe, we will learn to align two buttons in a border.
How to do it…
In this recipe, follow the next steps:
- In the KV file, provide the
anchor_x
andanchor_y
properties. - Define two buttons using the following code:
<MyW>: anchor_x: 'right' anchor_y: 'bottom' Button: id: label1 size_hint: .2, .2 text: 'B1' Button: id: label2 size_hint: .1, .1 text: 'B2'
- In the Python file, define a class as an
AnchorLayout
reference for the rule of the KV file using the following code:import kivy from kivy.app import App from kivy.uix.anchorlayout import AnchorLayout from kivy.clock import Clock class MyW(AnchorLayout): pass class e11App(App): def build(self): return MyW() if __name__ ...
Get Kivy Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.