Lesson-8: Tkinter Grid Geometry Manager
Tkinter Grid Geometry Manager
This geometry manager is suitable for interfaces where window tools will be sorted in a “grid” format. Let’s continue our lesson through the following example.
import tkinter as tk
import random
pencere=tk.Tk()
pencere.geometry("200x200+150+150")
ad = tk.Label(text="ADINIZ: ")
ad.grid(row=0,column=0)
soyad = tk.Label(text="SOYADINIZ: ")
soyad.grid(row=1,column=0)
numara = tk.Label(text="NUMARANIZ: ")
numara.grid(row=2,column=0)
ad_giris = tk.Entry()
ad_giris.grid(row=0,column=1)
soyad_giris = tk.Entry()
soyad_giris.grid(row=1,column=1)
numara_giris = tk.Entry()
numara_giris.grid(row=2,column=1)
pencere.mainloop()
In the example above, there are 3 label tools and 3 entry widgets. In previous examples, we put these tools in the window with the pack() command. In this example, we will use the grid command. The Grid command takes 2 parameters in parentheses. These are” row” and “column” values.
ROW:
The word means “line” in English. With this option, we will determine which row the window tool will be located in.
COLUMN:
With this option, we will determine which column our window tool will be located on the window.
ad = tk.Label(text="ADINIZ: ")
ad.grid(row=0,column=0)
ad_giris = tk.Entry()
ad_giris.grid(row=0,column=1)
In the short code example, the label row and column values named name are 0. Entry is 1 if row 0 is column. In two tools, it is located in the zero row, and the label is in the zero column Entry 1.it is located in the column. So they are located side by side.
Screen Shot:
As you can see, with the help of this grid() method, we can make more fine adjustments compared to the pack() method. the “grid ()” method allows us to specify the coordinates of our window tool more precisely.