Kivy is a platform independent GUI tool in Python. As it can be run on Android, IOS, linux and Windows etc. It is basically used to develop the Android application, but it does not mean that it can not be used on Desktops applications.
The AnchorLayout aligns its children to a border (top, bottom, left, right) or center. The class given below is used to implement the anchor layout.
AnchorLayout can be initialized with parameters:
anchor_x Parameters can be passed: “left”, “right” and “center”. anchor_y Parameters can be passed:“top”, “bottom” and “center”.
to select the place where the widgets are placed in the parent container.
There are 9 different layout regions where the Anchorlayout can be placed for effect:
Top-left, top-center, top-right, center-left, center-center, center-right, bottom-left, bottom-center and bottom-right.
Basic Approach: 1) import kivy 2) import kivyApp 3) import gridlayout(not necessary according to requirement) 4) import Anchorlayout 5) Set minimum version(optional) 6) create Layout class 7) create App class 8) Set up .kv file 9) Return the instance of layout class 10) Run an instance of the Appclass
In the below example code, we have used a
GridLayout as our root widget class. The GridLayout, will be the parent of 9 AnchorLayouts. The 9 AnchorLayouts will be anchored at the 9 different anchoring positions i.e we are using all the 9 Anchorlayout positions in a single program with the help of 9 Buttons.
Implementation of the Approach:
.kv file –
- Python| AnchorLayout in Kivy
- Python | Kivy .kv File
- Python | PageLayout in Kivy using .kv file
- Python | Canvas in Kivy using .kv file
- Python | TextInput in kivy using .kv file
- Python | Accordion in kivy using .kv file
- Python | StackLayout in Kivy using .kv file
- Python | File chooser in kivy
- Python | FloatLayout in Kivy using .kv file
- Python | Animation in Kivy using .kv file
- Python | ScreenManager in Kivy using .kv file
- Python | Working with buttons in Kivy with .kv file
- Python | Switch widget in Kivy using .kv file
- Python | Spinner widget in Kivy using .kv file
- Python | Popup widget in Kivy using .kv file
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : ManasChhabra2