Błażej Michalik
Błażej Michalik

Reputation: 5055

Python tkinter: hiding a widget after it was place()d

How to hide a widget (frame) after it's been shown with .place()?

For example:

lbl = tkinter.Label(root, text="A label")
lbl.place(relx=0.5, rely=0.5)
lbl.?() # Hide the label

Upvotes: 4

Views: 4172

Answers (2)

I just want to add some notes that I found useful in my case.

I was using an example where the person assigned the label in one line just appending the .place(x=10,y=20) on the end. When done this way, trying to use lbl.place_forget() failed saying there was no such attribute.

So, creating the label in two lines as shown in this thread is important.

Also, note that place can be either relative (relx=0.5, rely=0.5) or absolute (x=10, y=20)

To restore the label after forget, you just need to remind Tkinter where the label was with lbl.place(relx=0.5, rely=0.5)

Upvotes: 0

Błażej Michalik
Błażej Michalik

Reputation: 5055

The answer is .place_forget():

lbl = tkinter.Label(root, text="A label")
lbl.place(relx=0.5, rely=0.5)
lbl.place_forget() # Hide the label

Upvotes: 10

Related Questions