ANN: Thinking in Tkinter

Stephen Ferg steve at ferg.org
Wed Sep 11 10:16:20 EDT 2002


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> (what Joseph was doing was binding the button to the <Button-1> event,
> e.g. mybutton.bind("<Button-1>", afunction))
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
That example was mine.  It was based on the discussion in John Grayson's
book (p. 108), where Grayson says that (for mouse-button events) 
binding the action to <Button-1> has the same effect as
binding using "command".

But it seems that really is incorrect.  On 
http://www.tcl.tk/man/tcl8.4/TkCmd/button.htm#M6
it says that the "command is typically invoked when mouse 
button 1 is released over the button window."  So it looks like the
correct mouse-button binding to replace "command" would be to bind to 
<ButtonRelease-1>.

But it sounds like you are saying that even binding to 
<ButtonRelease-1> is not standard behavior ...

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Alas, too true. Button-1 fires when the mouse button is pressed (very 
nonstandard behavior) and ButtonRelease fires when the mouse button is 
released even if the mouse is no longer over the Button object. I don't 
know of any event binding that does a proper job of emulating the 
standard behavior of pressing a button. Button(command=...) is the way 
to go for this.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

What is the standard behavior?  Not <Button-Release-1>? 

Is there any place where definitions or explanations
or discussions of standard button behavior are written down
and available? A book? A Web page?

Do you know if "command" (at least for 
mouse-button behavior, ignoring
its response to keypresses) does anything other than 
simply respond to <Button-Release-1>?  


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Actually, I use a minor variant ...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Thanks.  This is useful information.  

Also mucho thanks for something else.  I looked at your SUMMARY about 
a month ago and on your recommendation I picked up a copy of 
Brent Welch's "Practical Programming in Tcl and Tk".  It has been 
immensely helpful.  A good tip! :-)



More information about the Python-list mailing list