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
It is quite confusing to understand the difference between Stack and Boxlayout.
StackLayout can organize widgets with more complexity than BoxLayout
Boxlayout can organize widgets either in a vertical or horizontal way. But with the
StackLayout, you can combine the orientations. There are 4 row-wise and 4 column wise orientations.
More flexible that Boxlayout(1D) 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)
The four row-wise orientations and four column-wise orientation are shown in below pictures.
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 App class 7) return widget 8) Run an instance of the class
Implementation of the Approach:
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 31 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:
- Python | StackLayout in Kivy using .kv file
- Python | Canvas in kivy
- Python | Kivy .kv File
- Python | Animation in Kivy
- Python | PageLayout in Kivy
- Python| AnchorLayout in Kivy
- GridLayouts in Kivy | Python
- Python | Switch widget in Kivy
- Python | PageLayout in Kivy using .kv file
- Python | Add image widget in Kivy
- Python | Popup widget in Kivy
- Python | Add Label to a kivy window
- Python | Working with buttons in Kivy
- Python | Float Layout in Kivy
- Python | Ellipse (different polygons) in Kivy
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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