tkinter button state = DISABLED
James Stroud
jstroud at mbi.ucla.edu
Mon May 14 19:59:48 EDT 2007
rahulnag22 at yahoo.com wrote:
> I have created a button widget with a button click binding. The button
> initially has a state=disabled. I can see the greyed out version of
> the button in the GUI. But If I click on the button it still invokes
> the callback/binding function.
>
> Any suggestions as to why the callback is being invoked even though
> the button has a disabled state. It looks like-
>
> b=Button(frame, text = "Button", state = 'disabled')
>
> b.bind("<ButtonRelease-1>",
> lambda
> event :
> function()
> )
>
> Thanks
> Rahul
>
DISABLED refers to the whether the function supplied in the "command"
parameter is called when the button is pressed, other bindings are
irrelevant, so you will need code to re-bind any events you have bound
when the button is "disabled". So its better to just use the "command"
parameter rather than binding mouse events.
An exception is Checkbutton, where you might want to bind
<ButtonRelease-1> and then query the button's state (or the state of an
IntVar associated with it) to make a decision--if you want a GUI to
respond real-time to user events.
James
More information about the Python-list
mailing list