Learn Before
Concept
Grid System
We use pack() method to put widgets on the window. But it does not let us control where we want to place the widget. To position the widgets (label, entry, button etc) in the window, we can use the grid system to position widgets with more control. We assign rows and columns to the widgets. Rows and Columns start from 0. For example if we want a button at 1st row and 2nd column, we use row=1, column=2. With the .grid() method, we dont need to use pack()
```python import tkinter as tk window = tk.Tk() window.geometry("500x200") #creating labels label1 = tk.Label(text="Name:") label2 = tk.Label(text="Age:") label3 = tk.Label(text="School:") label4 = tk.Label(text="Phone#") button = tk.Button(text="Submit", foreground="red") #creating entry entry1 = tk.Entry() entry2 = tk.Entry() entry3 = tk.Entry() entry4 = tk.Entry() #positioning the widgets using the grid system label1.grid(row=0, column=0) entry1.grid(row=0, column=1) label2.grid(row=1, column=0) entry2.grid(row=1, column=1) label3.grid(row=0, column=2) entry3.grid(row=0, column=3) label4.grid(row=1, column=2) entry4.grid(row=1, column=3) button.grid(row=2, column=2) window.mainloop()

0
1
Updated 2021-08-17
Tags
Python Programming Language
Data Science