Reputation: 15
After creating a Label object in tkinter I tried to remove label using pack_forget attribute. But script not working. I am using python version 2.7.9 in raspbian. Code is like:
visual = Tkinter.Tk()
sample = Label(visual, text="Hello python!")
sample.pack()
visual.update()
time.sleep(2)
sample.pack_forget()
visual.update()
Upvotes: 0
Views: 6761
Reputation: 22754
The effect of pack_forget()
is render the widget on which it is applied to be invisible (like it is falsely removed). The proof is that if you add, after visual.update()
this line print(sample.winfo_exists())
it will print you 1, which thing means your label still exists in reality. So to effectively get rid of your label, you must use sample.destroy()
instead. In this later case, the line print(sample.winfo_exists())
will print 0 meaning your label called sample does not exist any more.
Upvotes: 1