In Tkinter is there any way to make a widget not visible?

rectangletangle picture rectangletangle · Sep 29, 2010 · Viewed 122.3k times · Source

Something like this, would make the widget appear normally:

Label(self, text = 'hello', visible ='yes') 

While something like this, would make the widget not appear at all:

Label(self, text = 'hello', visible ='no') 

Answer

luc picture luc · Sep 29, 2010

You may be interested by the pack_forget and grid_forget methods of a widget. In the following example, the button disappear when clicked

from Tkinter import *

def hide_me(event):
    event.widget.pack_forget()

root = Tk()
btn=Button(root, text="Click")
btn.bind('<Button-1>', hide_me)
btn.pack()
btn2=Button(root, text="Click too")
btn2.bind('<Button-1>', hide_me)
btn2.pack()
root.mainloop()