AnchorLayout aligns the children to a border or center. In this recipe, we will learn to align two buttons in a border.
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__ == '__main__': e11App().run()