Tkinter Part - 5 | Introduction to grid() with its parameter and example in Tkinter python| MUST WATCH
CODE:
#grid()
#grid()
'''
The grid geometry manager uses the concepts of rows and columns to arrange the widgets.
Each row and column in the grid is identified by an index.
By default, the first row has an index of zero,
the second row has an index of one, and so on.
The indexes of rows and columns in a grid don’t have to start at zero.
In addition, the row and column indexes can have gaps.
you can have a grid whose column indexes are 1, 2, 10, 11, and 12.
To place multiple widgets in a cell,
you use a Frame or LabelFrame to wrap the widgets
and place the Frame or LabelFrame on the cell.
'''
#Setting up the grid
'''
you’ll need to configure the rows and columns of the grid.
Tkinter provides you with two methods for configuring grid rows and columns:
container.columnconfigure(index, weight)
container.rowconfigure(index, weight)
The columnconfigure() method configures the column index of a grid.
The weight determines how wide the column will occupy, which is relative to other columns.
For example, a column with a weight of 2 will be twice as wide as a column with a weight of 1.
'''
#Padding
'''
To add paddings between cells of a grid, you use the padx and pady options.
The padx and pady are external paddings
grid(column, row, sticky, padx, pady)
To add paddings within a widget itself, you use ipadx and ipady options.
The ipadx and ipady are internal paddings:
grid(column, row, sticky, padx, pady, ipadx, ipady)
'''
from tkinter import *
root window
root = Tk()
root.geometry("240x100")
root.title('Login')
root.resizable(0, 0)
configure the grid
root.columnconfigure(0, weight=1)
root.columnconfigure(1, weight=3)
username
username_label = Label(root, text="Username:")
username_label.grid(column=0, row=0, sticky=W, padx=5, pady=5)
username_entry = Entry(root)
username_entry.grid(column=1, row=0, sticky=E, padx=5, pady=5)
password
password_label = Label(root, text="Password:")
password_label.grid(column=0, row=1, sticky=W, padx=5, pady=5)
password_entry = Entry(root, show="*")
password_entry.grid(column=1, row=1, sticky=E, padx=5, pady=5)
login button
login_button = Button(root, text="Login")
login_button.grid(column=1, row=3, sticky=E, padx=5, pady=5)
root.mainloop()
🎓 Subscribe & Stay Tuned:
👍 Like, Share, and Comment:
🔗 Connect with us:
GUI Playlist: • Building GUI Applications with Tkinter | S...
Python Playlist : • Python Programming Essentials | Study2Shar...
Visit My YouTube channel : https://www.youtube.com/ @Study2Share
Thank you for watching.
-----------------------------------------------------------
Like - Share - Comment - Subscribe.
------------------------------------------------------------
#python #programming #GUI #Tkinter #grid() #pythonprogramming #pythontutorial #pythonbasics #pythondatatypes #pythonforbeginners #pythonbeginner #python3 #pythonadvanced #python #pythonexamples #pythonexercises #programming #programmingpython #pythondevelopers #pythondevelopment #pythondeveloper #pythonseries #pythonmastery #pythonmodule #pythonfunction #pythonmethods #pythondictionary #pythonkey #pythonvalue #pythoncoder #pythoncode #top10 #study2share #studytwoshare #studyshare #study #share #pratik #shah