By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,621 Members | 1,101 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,621 IT Pros & Developers. It's quick & easy.

tkinter button state = DISABLED

P: n/a
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

May 14 '07 #1
Share this Question
Share on Google+
8 Replies


P: n/a
ra********@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()
)
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

May 14 '07 #2

P: n/a
On May 14, 12:01 pm, Peter Otten <__pete...@web.dewrote:
rahulna...@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()
)

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

May 14 '07 #3

P: n/a
En Mon, 14 May 2007 17:46:32 -0300, <ra********@yahoo.comescribió:
On May 14, 12:01 pm, Peter Otten <__pete...@web.dewrote:
>rahulna...@yahoo.com wrote:
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.

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

--
Gabriel Genellina

May 14 '07 #4

P: n/a
ra********@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-1and 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
May 15 '07 #5

P: n/a
"Gabriel Genellina" <ga*******@yahoo.com.arwrote:
>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

May 16 '07 #6

P: n/a
En Wed, 16 May 2007 03:22:17 -0300, Hendrik van Rooyen
<ma**@microcorp.co.zaescribió:
"Gabriel Genellina" <ga*******@yahoo.com.arwrote:
>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.
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.

--
Gabriel Genellina

May 16 '07 #7

P: n/a
"Gabriel Genellina" <ga*******@yahoo.com.arwrote:

>En Wed, 16 May 2007 03:22:17 -0300, Hendrik van Rooyen
<ma**@microcorp.co.zaescribió:
> "Gabriel Genellina" <ga*******@yahoo.com.arwrote:
>>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.

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

May 17 '07 #8

P: n/a
On Thu, 17 May 2007 09:30:57 +0200, Hendrik van Rooyen
<ma**@microcorp.co.zawrote:
"Gabriel Genellina" <ga*******@yahoo.com.arwrote:
>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.

No command is ok and you have described it right - its ButtonRelease that
seems broken to me
Apparently, this behaviour is the intended one, at least for buttons; see:
http://www.tcl.tk/man/tcl8.4/TkCmd/bind.htm#M11

As for the question "why?", maybe you should ask it on the c.l.tcl
newsgroup?
--
python -c "print ''.join([chr(154 - ord(c)) for c in
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
May 18 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.