tkinter button state = DISABLED

Hendrik van Rooyen mail at microcorp.co.za
Tue May 22 02:16:15 EDT 2007


 "Hamilton, William " <w...l1 at en...y.com> wrote:


> > From: Eric Brunel
> On Thu, 17 May 2007 09:30:57 +0200, Hendrik van Rooyen
> > <mail at microcorp.co.za> wrote:
> > >  "Gabriel Genellina" <gagsl-py2 at yahoo.com.ar> wrote:
> > >> 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?
> 
> The difference between bind and the button's command parameter makes sense
> to me.  You'd use bind to create something like a right-click menu, where
> you want the same thing to happen whether the button is disabled or not.
> You use the command parameter when you care about the state of the button.
> 

That is a good point.

What I was actually nattering on about was the unexpected behaviour of the
ButtonRelease binding - from its name, you would expect it to call the bound
function when a click is released on the button.  It does not do that.

Having been told that its the expected behaviour, I can imagine it to be useful
in "drag and drop" scenarios, to implement something from the source side -
a "thrower" - as opposed to the "catcher" type of behaviour that its name
suggests.

- Hendrik




More information about the Python-list mailing list