Tkinter event

Fredrik Lundh fredrik at
Sat Feb 10 08:49:51 EST 2001

"knock knock" <none at> wrote:
> got a canvas with items (lines). the mouseover event should give a specifc
> desciption for every item in the canvas. so i did a mouseover bind to a
> unique tag for every item! the idea is to make function that listens to the
> event and look ups the description. how can this method find out which item
> (tag) sent the event?? this must be possible, right?

it's probably easier (for everyone, including Tk) to use a canvas-
level binding, and do the lookup in the event handler:

def eventhandler(event):
    canvas = event.widget
    x = canvas.canvasx(event.x)
    y = canvas.canvasx(event.y)
    items = canvas.find_overlapping(x, y, x+1, y+1)
    for item in items:
        tags = canvas.gettags(item)

Cheers /F

More information about the Python-list mailing list