disabling button

D

devnew

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
 
F

Fredrik Lundh

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>
 
D

damonjulian

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top