473,466 Members | 1,388 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 2918
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: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.