Here we are providing basic tutorial on GridLayout
First consider the code given below.
Explanation of above code
from tkinter import *
root = Tk()
label_1 = Label(root, text="Name")
label_2 = Label(root, text="Password")
entry_1 = Entry(root)
entry_2 = Entry(root)
Below section will give an explanation of the above Tkinter program. If you want to start from the beginning, please visit our Introduction to GUI
This can be assumed as a way to create an input field just like in form. In above code, two entries i.e input fields are there in the root
, one for label Name
and one for label Password
. An entry can be created using Entry
pre-defined function in Tkinter.
It is a way of distributing the layout in grids.
This is done using grid
pre-defined function in Tkinter. For example, instead of using pack()
is being used.
For label Name
, grid is set for 0th row in the window, column is set to 0 by default. So, Name
comes in 0th row and 0th column of the window.
Similarly, input field for Name
is in 0th row and 1st column.
is in 1st row and 0th column.
Input field for Password
is in 1st row and 1st column.