tkinter button state = DISABLED

R

rahulnag22

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
 
P

Peter Otten

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()
)

Well, the /mouse/ button /was/ released. Do you know about the alternative?

b = Button(..., command=function) # no bind(), no lambda

It behaves like you expect.

Peter
 
R

rahulnag22

Well, the /mouse/ button /was/ released. Do you know about the alternative?

b = Button(..., command=function) # no bind(), no lambda

It behaves like you expect.

Peter


So, then is it right to say that for a widget like button widget on
occurance of a 'event' the function which is bound to this event is
invoked, even if the button widget has its 'state' option set to
'disabled'. I was assuming that if the button widget has state =
'disabled' then even on a button event the binding function wont be
invoked.
I will take a look at the alternative code you suggested above too.

Thanks
Rahul
 
G

Gabriel Genellina

So, then is it right to say that for a widget like button widget on
occurance of a 'event' the function which is bound to this event is
invoked, even if the button widget has its 'state' option set to
'disabled'. I was assuming that if the button widget has state =
'disabled' then even on a button event the binding function wont be
invoked.
I will take a look at the alternative code you suggested above too.

Maybe there is a confusion here. You code above means that, when the event
"The leftmost MOUSE BUTTON was released" happens over your BUTTON WIDGET
b, your function will be called.
The "alternative code" suggested is the right way; the "command" is fired
when the mouse button is pressed inside the widget AND then released
inside the SAME widget (and the button is not disabled).
 
J

James Stroud

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
 
H

Hendrik van Rooyen

Gabriel Genellina said:
Maybe there is a confusion here. You code above means that, when the event
"The leftmost MOUSE BUTTON was released" happens over your BUTTON WIDGET
b, your function will be called.

I have never seen this working in Tkinter, unless the button was pressed on the
widget
in question - and worse, once you have clicked down on a ButtonRelease binding
you can move the mouse pointer anywhere you like, even out of the application
and when you release it, the bound function is called...

Its either a bug or a feature, I don't know.

- Hendrik
 
G

Gabriel Genellina

En Wed, 16 May 2007 03:22:17 -0300, Hendrik van Rooyen
I have never seen this working in Tkinter, unless the button was pressed
on the
widget
in question - and worse, once you have clicked down on a ButtonRelease
binding
you can move the mouse pointer anywhere you like, even out of the
application
and when you release it, the bound function is called...

Its either a bug or a feature, I don't know.

Uhmm... I'm not sure I understand you completely. I only said that the
"command" is fired only when the mouse button is pressed on the widget,
AND released inside the same widget. If both events don't happen in the
same widget, "command" won't fire. Maybe you are saying the same thing...
anyway I'm not a Tk expert.
 
H

Hendrik van Rooyen

En Wed, 16 May 2007 03:22:17 -0300, Hendrik van Rooyen


Uhmm... I'm not sure I understand you completely. I only said that the
"command" is fired only when the mouse button is pressed on the widget,
AND released inside the same widget. If both events don't happen in the
same widget, "command" won't fire. Maybe you are saying the same thing...
anyway I'm not a Tk expert.

No command is ok and you have described it right - its ButtonRelease that
seems broken to me

- Hendrik
 

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

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,169
Latest member
ArturoOlne
Top