Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

tkinter: canvas event handling problem

6 views
Skip to first unread message

Garry Hodgson

unread,
Nov 19, 1999, 3:00:00 AM11/19/99
to

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 )
canvas.pack()

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

root.mainloop()

--
Garry Hodgson And it's just a box of rain
Software Innovation Services I don't know who put it there
AT&T Labs Believe it if you need it
ga...@sage.att.com Or leave it if you dare

0 new messages