Do you think IIT Guwahati certified course can help you in your career?
No
Introduction
Kivy is a GUI tool in Python, independent of the platform, to develop Android applications and can be used for Desktop applications development. It can be run on Windows, iOS, Android, and Linux.
The StackLayout is a layout method in Kivy used to arrange widgets horizontally or vertically, irrespective of their size, in a layout. Horizontally can be left-to-right or right-to-left, and vertically, top-to-bottom or bottom-to-top. And in this article, we will discuss StackLayout, some features, and a few programs to justify the points.
Let us see a brief explanation of StackLayout.
StackLayout
As discussed, StackLayout arranges children's widgets (like buttons) horizontally or vertically in a layout, as many as the layout can fit it. But to use StackLayout, first, we need to import it from Kivy by the following command:
Code:
from kivy.uix.stacklayout import StackLayout
You can also try this code with Online Python Compiler
But sometimes, it's quite confusing to differentiate BoxLayout from StackLayout. Boxlayout is a 1'Dimensional means it can only organize the widgets either horizontally or vertically. The orientation of StackLayout is 2'Dimensional and can organize the widgets with more complexity. It has four row-wise and four column-wise orientations.
The output above shows 'lr-tb' orientation as we gave the parameter in "StackLayout(orientation =' lr-tb')". We can also change the orientation row-wise and column-wise accordingly. For row-wise we can use these parameters -‘rl-bt’ , ‘rl-tb’ , ‘lr-bt’ , ‘lr-tb’ and for column-wise we can use given parameters- ‘bt-rl’ , ‘bt-lr’ , ‘tb-rl’ , ‘tb-lr’.
Below is the output for all orientations.
Row-wise orientation methods-
Change the orientation in following code
Slayout = StackLayout(orientation = ‘lr-tb’)
You can also try this code with Online Python Compiler
Kivy is a cross-platform which supports Linux, OSX, Windows, Android, and iOS.
How can we import StackLayout?
By using the following command: from kivy.uix.stacklayout import StackLayout
Conclusion
In this article, we have extensively discussed StackLayout. At first, we have seen some brief explanations about StackLayout. Then we have seen the approach to creating a StackLayout. And at last, program to create a StackLayout.