[Tkinter-discuss] How to distinguish canvas items (2)

Ben Koopmanschap ben.koopmanschap at gmail.com
Sun Apr 19 20:18:34 CEST 2009

Hello everyone!

Just discovered the trick to bind and distinguish specific items on
the canvas in Tkinter :)

According to 'Programming python' from Mark Lutz, page 541 it is
possible with the widget.find_closest method to bind a specific item
on a canvas. Just what I've been looking for! So I can change my
formerly posted snippet to:

def mouseDown(self, event):
        # remember where the mouse went down
        self.lastx = event.x
        self.lasty = event.y
        print event.widget.find_closest(event.x, event.y)     #  <--
this does the trick

Tested this out and it works very well!

Hope this will others pointing in the right direction!

With regards,
- Ben

More information about the Tkinter-discuss mailing list