grid() in tkinter in python by R4R Team

For display or attached the widget to the window screen, we have a three way in tkinter:
1. pack()
2. grid()
3. place()

Pack():

-It put the widget according to the Left,Right,Top,Bottom.

Grid():

-It put the widget according to rows and columns format.

place():

-It put the widget according to (x,y) coordinate.

Grid():

Syntax-

widget.grid(row=value,column=value)



program-

from tkinter import *
#create a window screen
win=Tk()
win.geometry("400x350")

l=Label(win,text="Text 1",fg="white",bg="blue",bd=20)
l.grid(row=0,column=0)

l=Label(win,text="Text 2",fg="white",bg="green",bd=20)
l.grid(row=1,column=1)

l=Label(win,text="Text 3",fg="white",bg="red",bd=20)
l.grid(row=2,column=2)

l=Label(win,text="Text 4",fg="white",bg="black",bd=20)
l.grid(row=3,column=3)

#hold the screen
win.mainloop()


output-



-In this program, we create a window screen by win=Tk() and hold the screen by win.mainloop() in the last.
-We create a four Label at different position by grid() layout.
-grid layout put the content in tables format.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!