Place_forget() method using Tkinter in Python
Last Updated :
01 Aug, 2020
To hide or forget a widget from the parent widget or screen in tkinter, the place_forget() method is used on that widget based on place geometry management.
Syntax: widget.place_forget()
Parameter: None
Return: None
Below is the implementation :
Python3
from tkinter import *
from tkinter.ttk import *
root = Tk()
root.geometry( "150x100" )
label = Label(root, text = "LABEL" )
label.place(relx = 0.4 , y = 5 )
b1 = Button(root, text = "hide text" ,
command = lambda : label.place_forget())
b1.place(relx = 0.3 , y = 30 )
b2 = Button(root, text = "retrieve text" ,
command = lambda : label.place(
relx = 0.4 ))
b2.place(relx = 0.3 , y = 50 )
root.mainloop()
|
Output:
After hiding:
After retrieving:
Note: There are other methods pack_forget() and grid_forget() that work the same way as forget_pack() and forget_grid() .
Share your thoughts in the comments
Please Login to comment...