How could I hide an existing Label when a button is clicked in Python(Tkinter)?
This really depends on the geometry manager you used. If you use
lbl = Tkinter.Label(parent)
to create the label, you will use one of the following to hide it.
lbl.grid_forget()
lbl.pack_forget()
lbl.place_forget()
edit (working example)
import tkinter
class MyClass(tkinter.Frame):
def __init__(self,parent, *args, **kwargs):
tkinter.Frame.__init__(self, parent, *args, **kwargs)
self.btn = tkinter.Button(self,text='Don\'t push me',command=self.buttonCmd)
self.btn.grid(row=0,column=0,sticky='nwes')
self.lbl = tkinter.Label(self,text='Push it, it\'s fun')
self.lbl.grid(row=0,column=1,sticky='nwes')
def buttonCmd(self,*args,**kwargs):
self.lbl.grid_forget()
root = tkinter.Tk()
MyFrame = MyClass(root)
MyFrame.pack(expand='true',fill='both')
root.mainloop()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With