bug in tkinter canvas event handling?

Ivan Van Laningham ivanlan at callware.com
Tue Nov 30 09:48:57 EST 1999

Hi All--

Doug Hellmann wrote:
> "Garrett G. Hodgson" wrote:
> >
> > ok, i'm back with another tk problem.
> > what i want to do is attach a callback to a shape in a canvas
> > that will tell me which domain level object was picked.
> >
> > seems simple, but i don't get what i expect.  in particular,
> > if i press a mouse button while pointing to one object, then drag
> > to another and release, the release event callback tells me i
> > was pointing to the first object.  i've distilled it down to a
> > small test case, attached below.
> >
> > this seems like a bug to me, but experience has shown that it's
> > probably a misconception on my part about how the event handling
> > is supposed to work.
> This behavior surprised me at first, too.  It's as though the first
> canvas object is grabbing the pointer so that all events go to it.  I
> got around the problem by looking for the x,y coords of the release
> event and then finding the object(s) under that point on the canvas.

Actually, this isn't a bug.  All windowing systems (the ones I know
about, anyway) behave this way by design; the down-click does indeed
grab the mouse pointer, and does not let go until the up-click (or is
that up-chuck?).  You can see this behaviour even in windows, which
hacks away at expected pointer motion with gleeful abandon.  Click on a
scrollbar, begin moving it, move the pointer out of the scrollbar,
*watch the scrollbar snap to its previous position*, move the pointer
back into the scrollbar, and finally *watch the scrollbar snap back
under the pointer.*  This is repulsive and incorrect behaviour <0.9
barf>, but it couldn't be done without a mouse pointer grab by the
object underneath the pointer on the down-click.

<m$-doing-the-wrong-thing-for-the-right-reasons>-ly y'rs,
Ivan Van Laningham
Callware Technologies, Inc.
ivanlan at callware.com
ivanlan at home.com
See also: 
Army Signal Corps:  Cu Chi, Class of '70
Author:  Teach Yourself Python in 24 Hours

More information about the Python-list mailing list