Python Forum
Hide button when clicked - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: Hide button when clicked (/thread-14915.html)



Hide button when clicked - frequency - Dec-24-2018

self.w3=Button(self.root,text="This must dissapear when clicked ",font="Arial 12",bg="#d9d9d9",command=self.check)
self.w3.grid(row=8,column=1)
This button calls a an other function called "check",but how can i make it so when it gets clicked,it dissapears?
I am reading about binds and the "configure" method right now.Any ideas?


RE: Hide button when clicked - Larz60+ - Dec-24-2018

since you didn't specify which GUI you were using, and it looks like tkinter, I will assume that is the case.
You should also post at minimum a snippet that will run, and any errors encountered (verbatim)

try in check routine (untested as not enough code to run):
def check(self):
   ...
   self.w3.lower()
to make it re-appear self.w3.lift()


RE: Hide button when clicked - frequency - Dec-24-2018

Hello!.I am using tkinter,you are correct.I tried your code but did not make it work. This a snippet.Enough to fix the issue,i guess.

def start(self):
        self.w=Label(self.root,text="Πρόσθεση πινάκων παραδείγματα",font="Arial 12")
        self.w.grid(row=1,column=1)
        self.w1=Label(self.root,text="Διάλεξε τις διαστάσεις του πρώτου πίνακα",font="Arial 12")
        self.w1.grid(row=2,column=1)
        self.s1=Label(self.root,text="X:",font="Arial 10")
        self.entry1=Entry(self.root,font="Arial 12",bg="#d9d9d9",width=5)
        self.entry1.grid(row=3,column=1)
        self.s2=Label(self.root,text="Y:",font="Arial 10")
        self.s2.grid(row=4,column=1)
        self.entry2=Entry(self.root,font="Arial 12",bg="#d9d9d9",width=5)
        self.entry2.grid(row=4,column=1)
        self.w2=Label(self.root,text="Διάλεξε τις διαστάσεις του δεύτερου πίνακα",font="Arial 12")
        self.w2.grid(row=5,column=1)
        self.s3=Label(self.root,text="X:",font="Arial 10")
        self.s3.grid(row=6,column=1)
        self.entry3=Entry(self.root,font="Arial 12",bg="#d9d9d9",width=5)
        self.entry3.grid(row=6,column=1)
        self.s4=Label(self.root,text="Y:",font="Arial 10")
        self.s4.grid(row=7,column=1)
        self.entry4=Entry(self.root,font="Arial 12",bg="#d9d9d9",width=5)
        self.entry4.grid(row=7,column=1)
        self.w3=Button(self.root,text="Must be gone when clicked",font="Arial 12",bg="#d9d9d9",command=self.multi)
        self.w3.grid(row=8,column=1)
the self.multi command is this def
    def multi(self):
        self.check() #verifies some variables,ignore
        self.w3.lower()# tries to minimize the button
        

def multi(self):
        self.check()
        self.w3['state']=DISABLED ##lockes the button upon click!
Managed to do it!.I locked it.Its ok and works. Thanks!