Skip to content
Related Articles

Related Articles

Improve Article

place_info(), pack_info() and grid_info() methods in Tkinter

  • Last Updated : 01 Aug, 2020
Geek Week

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




# Importing all functions/classes
# from tkinter module 
from tkinter import *
  
# toplevel window 
root = Tk() 
  
# setting window size
root.geometry("810x350")
  
# create a Label widget whose
# place info is to be obtained
rect = Label(root, 
             text = "MY PLACE INFO IS SHOWN BELOW"
             bg = "pink")
  
# place a widget in a specific 
# position in the parent widget.
rect.place(rely = 0.1, relx = 0.2,
           relwidth = 0.6
           relheight = 0.3)
  
# widget displaying place info of rect
label = Label(root)
  
# place a widget in a specific
# position in the parent widget.
label.place(rely = 0.6)
  
# get a info of the place
label['text'] = rect.place_info()
   
# start the GUI
root.mainloop() 

Output:
 

place info method working

 

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




# Importing all functions/classes
# from tkinter module 
from tkinter import *
  
# toplevel window 
root = Tk() 
  
# create a Label widget whose 
# pack info is to be obtained
rect = Label(root, 
             text = "MY PACK INFO IS SHOWN BELOW",
             bg = "pink")
  
# placing them in a specific position
# in the parent widget.
rect.pack(expand = True)
  
# create a Label
label = Label(root)
  
label.pack()
  
label['text'] = rect.pack_info()
   
# start the GUI 
root.mainloop() 

Output:
 

pack info method working

 

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




# Importing all functions/classes 
# from tkinter module 
from tkinter import *
  
# toplevel window 
root = Tk() 
  
# widget whose grid info is to be obtained
rect = Label(root, 
             text = "MY GRID INFO IS SHOWN BELOW"
             bg = "pink")
  
# grid method is used for placing
# the widgets at respective positions
# in table like structure .
rect.grid(stick = N)
  
# create a label
label = Label(root)
  
label.grid()
  
label['text'] = rect.grid_info()
   
# start the GUI
root.mainloop() 

Output: 
 

grid info method working

 

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course




My Personal Notes arrow_drop_up
Recommended Articles
Page :