468,505 Members | 1,607 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,505 developers. It's quick & easy.

disabling button

using tkinter i created a gui and put a button on the frame

class mygui:
def __init__(self, parent):
...
self.okButton = Button(self.btnFrame)
self.okButton.configure(width=somewdth,text="OK",

anchor=W,disabledforeground="tan")
self.okButton.bind("<Button-1>",self.button1Click)

then in the buttonClick(self,event) i want to disable it till some
time consuming calculations are completed ..then i enable it

def button1Click(self, event):
self.okButton.configure(state=DISABLED)
print "ok disabled"
somebigcalculations()
self.okButton.configure(state=NORMAL)
print "ok enabled"

well,the button doesn't grey out when i click it ,though the print
staements are executed..
but if some error happens and program exits with some ioerror(say
errno2 file not found ..)then the button is shown as greyed out..

am i missing something here ? how can i get the button disabled and
greyed out on clicking it?

dn

Dec 22 '07 #1
3 2772
de****@gmail.com wrote:
then in the buttonClick(self,event) i want to disable it till some
time consuming calculations are completed ..then i enable it

def button1Click(self, event):
self.okButton.configure(state=DISABLED)
+ self.okButton.update_idletasks()
print "ok disabled"
somebigcalculations()
self.okButton.configure(state=NORMAL)
print "ok enabled"

well,the button doesn't grey out when i click it ,though the print
staements are executed..
but if some error happens and program exits with some ioerror(say
errno2 file not found ..)then the button is shown as greyed out..

am i missing something here ? how can i get the button disabled and
greyed out on clicking it?
when Tkinter needs to redraw things, it adds the redraw action to an
internal "task" queue. tasks in this queue are usually handled by the
main event loop, but that loop doesn't run when you do your big
calculations. an explicit call to "update_idletasks" will clear out the
task queue for you.

</F>

Dec 22 '07 #2
an explicit call to "update_idletasks" will clear out the
task queue for you.
</F>
it worked
Thanks F.L!!
dn
Dec 22 '07 #3


if you disable the button it can still respond to clicks? it only
greys out.. or is there a problem with my code here?

class MyApp:
def __init__(self,parent):
self.mainframe=Frame(parent)
self.mainframe.pack()
self.button1=Button(self.mainframe,bg="green")
self.button1.configure(text="1")
self.button1.pack(side=LEFT)
self.button1.bind("<Button-1>",self.buttonClick1)
self.button2=Button(self.mainframe,bg="yellow")
self.button2.configure(text="2")
self.button2.pack(side=LEFT)
self.button2.bind("<Button-1>",self.buttonClick2)
self.button3=Button(self.mainframe,bg="red")
self.button3.configure(text="3")
self.button3.pack(side=RIGHT)
self.button3.bind("<Button-1>",self.buttonClick3)

def buttonClick1(self,event):
print "ok clicked"
self.button2.configure(state=DISABLED)
self.button2.update_idletasks()

def buttonClick2(self,event):
print "2 clicked"

def buttonClick3(self,event):
print "3 clicked"
self.button2.configure(state=NORMAL)
#self.button2.update_idletasks()

root = Tk()
myapp = MyApp(root)
root.mainloop()
here when u click button 1 ,the button2 greys out but can still
respond to clicks..is there a way to truly disable it?

damon
Dec 22 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

22 posts views Thread by Papajo | last post: by
2 posts views Thread by Jeelz | last post: by
4 posts views Thread by Dan =o\) | last post: by
7 posts views Thread by Vignesh | last post: by
2 posts views Thread by dougawells | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.