473,221 Members | 1,794 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,221 software developers and data experts.

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 2913
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: Papajo | last post by:
This simple script counts up or down with a button click, now can it be modified so the count won't go below zero? Thanks, Joe <form> <input type=text name=amount size=4 value=>...
5
by: Lyn | last post by:
Hi, I hope someone can help. I have a main form which mostly fills the Access window. In the bottom half of this form I have a tab control to display various types of data related to the main...
4
by: Steve | last post by:
I have the MDI MFC application ported to .NET. Now this application include mixed managed/unmanaged code. The application displays progress dialog with the cancel button during lenghtly...
2
by: Jeelz | last post by:
Hi Guyz, Would appriciate any tip on disabling an ASP.NET LinkButton using client sided code like javascript. My Requirement is such that the user should be allowed to click on the link...
3
by: Paul | last post by:
Hi I am trying to create an "Update" button for my form. So far I have got it working fine, posting back and updating the record. Great! However, I now want to make it so that when a user...
4
by: Dan =o\) | last post by:
Hi guys, in the scenario where a user fills in a form, and clicks on a button to Save, there's a period of waiting (the slower the connection between client and server, the longer the delay)...
7
by: Vignesh | last post by:
I have tab control which has some TabPages. I want to enable or disable the tabpages based on some condition. It is possible to that. Thanks in advance.
2
by: dougawells | last post by:
Hi- I'm wanting to have a set of radio buttons disabled when a form is displayed, then if they check another specific radio button, those would become enabled. I've tried setting it via...
3
by: ChrisN | last post by:
Invoking a postback before a large ASP.NET page has fully rendered will often cause the page to crash. This is unhelpful and confusing to users. I'm wondering if I can overcome this by...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.