Using GridLayout
GridLayout is the way to organize the child widgets in a table. In this recipe, we will organize four buttons in a 2x2 grid.
How to do it…
Again we will use the KV file to set the widgets and the Python file to set the layout. To complete the recipe:
In the KV file, provide the number of columns and rows with column and row properties.
Also, define four buttons using the following code:
<MyW>: cols: 2 rows: 2 Button: id: label1 text: 'B1' Button: id: label2 text: 'B2' Button: id: label3 text: 'B3' Button: id: label4 text: 'B4'
In the Python file, import
GridLayout
.Define the root class as
GridLayout
. Use the following code to do that:import kivy from kivy.app import App from kivy.uix.gridlayout import GridLayout class MyW(GridLayout): pass class e8App(App): def build(self): return MyW() if __name__ == '__main__': e8App().run()
How it works…
In the KV file, we are...