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.
To use StackLayout firt import StackLayout by below command:
from kivy.uix.stacklayout import StackLayout
StackLayout arranges children vertically or horizontally, as many as the layout can fit. The size of the individual children widgets does not have to be uniform. There are 4 row-wise and 4 column wise orientations.
StackLayout Orientation (2D): - right to left or left to right - top to bottom or bottom to top - 'rl-bt', 'rl-tb', lr-bt', 'lr-tb'(Row wise) - 'bt-rl', 'bt-lr', 'tb-rl', 'tb-lr'(Column wise)
Basic Approach to create Stack layout : 1) import kivy 2) import kivyApp 3) import Button 4) import Stacklayout 5) Set minimum version(optional) 6) Create the StackLayout class 7) Create the App class 8) Set up .kv file (name same as App class) 9) return StackLayout Class 10) Run an instance of the class
Below is the implementation of row-wise orientations and column-wise orientation:
main.py file –
The name of the .kv file must be same as the App class i.e
.kv file –
This is for the orientation ‘lr-tb’. First the widgets are added left-to-right and then top-to-bottom.
Note: If want to change orientation just change the orientation in line no 04 of the
.kv file with any of the below orientations –
For row wise orientation use: -'lr-tb' -'lr-bt' -'rl-tb' -'rl-bt' For column wise orientation use: -'tb-lr' -'tb-rl' -'bt-lr' -'bt-rl'
Below there are picture output all the orientations above –
For row wise orientation use:
For column wise orientation use:
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. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course