bug in tkinter canvas event handling?

Garrett G. Hodgson garry at sage.att.com
Mon Nov 29 16:28:48 CET 1999

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.

anyone have any ideas?

------------------------- code follows -----------------------

from Tkinter import *

def Up( id ):
        print 'Up:', id

def Down( id ):
        print 'Down:', id

root = Tk()
canvas = Canvas( root )

Wid = 40
Hgt = 25
x, y = 100, 64
shape1 = canvas.create_oval( x-Wid, y-Hgt, x+Wid, y+Hgt, fill='red' )

x, y = 200, 64
shape2 = canvas.create_oval( x-Wid, y-Hgt, x+Wid, y+Hgt, fill='blue' )

canvas.tag_bind( shape1, "<1>",                 lambda e: Down( 'shape1'
) )
canvas.tag_bind( shape1, "<ButtonRelease-1>",   lambda e: Up( 'shape1' )

canvas.tag_bind( shape2, "<1>",                 lambda e: Down( 'shape2'
) )
canvas.tag_bind( shape2, "<ButtonRelease-1>",   lambda e: Up( 'shape2' )


Garry Hodgson			"Hey, mister, can ya tell me,
garry at sage.att.com		where a man might find a bed?"
Software Innovation Services	He just grinned and shook my hand,
AT&T Labs			"No", was all he said.

More information about the Python-list mailing list