place_info(), pack_info() and grid_info() methods in Tkinter
Last Updated :
01 Aug, 2020
To get all the information about the options of the geometry management of a widget place_info(), pack_info() and grid_info() methods in tkinter are used accordingly.
place_info() method
This method is used for getting information about geometry management of a widget like position and size of a window, either in absolute terms, or relative to another window.
Syntax : widget.place_info()
Parameter: None
Returns : Returns a dictionary of the info of the place options of the current widget
Code 1:
Python3
from tkinter import *
root = Tk()
root.geometry( "810x350" )
rect = Label(root,
text = "MY PLACE INFO IS SHOWN BELOW" ,
bg = "pink" )
rect.place(rely = 0.1 , relx = 0.2 ,
relwidth = 0.6 ,
relheight = 0.3 )
label = Label(root)
label.place(rely = 0.6 )
label[ 'text' ] = rect.place_info()
root.mainloop()
|
Output:
pack_info() method
This method is used for getting information about geometry management of a widget like expand, side, fill, padding values etc.
Syntax : widget.pack_info()
Parameter: None
Returns : Returns a dictionary of the info of the pack options of the current widget
Code 2:
Python3
from tkinter import *
root = Tk()
rect = Label(root,
text = "MY PACK INFO IS SHOWN BELOW" ,
bg = "pink" )
rect.pack(expand = True )
label = Label(root)
label.pack()
label[ 'text' ] = rect.pack_info()
root.mainloop()
|
Output:
grid_info() method
This method is used for getting information about geometry management of a widget like row number, column number ,rowsapn, columnspan, padding values etc.
Syntax : widget.grid_info()
Parameter: None
Returns : Returns a dictionary of the info of the grid options of the current widget
Code 3:
Python3
from tkinter import *
root = Tk()
rect = Label(root,
text = "MY GRID INFO IS SHOWN BELOW" ,
bg = "pink" )
rect.grid(stick = N)
label = Label(root)
label.grid()
label[ 'text' ] = rect.grid_info()
root.mainloop()
|
Output:
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...