Search code examples
pythontkinter

In Tkinter is there any way to make a widget invisible?


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') 

Solution

  • 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()