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 –
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.