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.
In this article, we are going to discuss how we can use layouts in layouts basically multiple Layouts the most basic example of it.
Most of the time we are able to use one layout but having difficulty to use multiple layouts.
In kivy there are many Types of Layouts:
- AnchorLayout: Widgets can be anchored to the ‘top’, ‘bottom’, ‘left’, ‘right’ or ‘center’.
- BoxLayout: Widgets are arranged sequentially, in either a ‘vertical’ or a ‘horizontal’ orientation.
- FloatLayout: Widgets are essentially unrestricted.
- RelativeLayout: Child widgets are positioned relative to the layout.
- GridLayout: Widgets are arranged in a grid defined by the rows and cols properties.
- PageLayout: Used to create simple multi-page layouts, in a way that allows easy flipping from one page to another using borders.
- ScatterLayout: Widgets are positioned similarly to a RelativeLayout, but they can be translated, rotate and scaled.
- StackLayout: Widgets are stacked in a lr-tb (left to right then top to bottom) or tb-lr order.
Note:You can use as many as you can in a single file.
Basic Approach to create multiple layouts in one file:
1) import kivy 2) import kivyApp 3) import BoxLayout 4) import 4) set minimum version(optional) 5) Extend the container class 6) set up .kv file : 7) create App class 8) return container class or layout 9) Run an instance of the class
Implementation of the Approach –
If you were using .kv file to make multiple layouts There is no need to import Gridlayout, Boxlayout, AnchorLayout, FloatLayout, StackLayout, PageLayout, Button etc. As .kv file supports all this as It has all this imported already. But if doing this without .kv file you must have to import these.
In this file we are creating/using all the layout as it is Simpler to built/ use all these in .kv file
.kv file of the code
- Python | How to use Multiple kv files in kivy
- How to use multiple UX Widgets in kivy | Python
- Python | Multiple Sliders widgets Controlling Background Screen or WindowColor in Kivy
- Python | Scatter in kivy
- Python | Bubble in kivy
- Python | Accordion in kivy
- GridLayouts in Kivy | Python
- Python | Canvas in kivy
- Python | Animation in Kivy
- Python| AnchorLayout in Kivy
- Python | Kivy .kv File
- Python | StackLayout in Kivy
- Python | PageLayout in Kivy
- Python | Canvas in Kivy using .kv file
- Python | Line (Canvas) 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.