[Tkinter-discuss] How to distinguish canvas items?

Ben Koopmanschap ben.koopmanschap at gmail.com
Sun Apr 19 17:41:34 CEST 2009

Hello everyone,

According to one of the many examples brought with the Tkinter
documentation, I am able to create some ovals on the canvas with:

fred = self.draw.create_oval(40, 40, 60, 60,
                                     fill="green", tags="selected")

followed by:

wilma = self.draw.create_oval(40, 40, 60, 60,
                                     fill="green", tags="selected")

and for creating the bindings:

self.draw.tag_bind(fred, "<Any-Enter>", self.mouseEnter)
self.draw.tag_bind(fred, "<Any-Leave>", self.mouseLeave)
self.draw.tag_bind(wilma, "<Any-Enter>", self.mouseEnter)
self.draw.tag_bind(wilma, "<Any-Leave>", self.mouseLeave)

Once created, a "mouseEnter" event behaves like what it has to do,
change the color of the CURRENT oval in this way:

def mouseEnter(self, event):
        # the CURRENT tag is applied to the object the cursor is over.
        # this happens automatically.
        self.draw.itemconfig(CURRENT, fill="red")

But what I want to know is how the individual ovals can distinguish
from each other, can anyone please tell me how the value (in this
case: Fred or Wilma) of one particular oval can be returned?

Thanks in advance!

Yours sincelery,
- Ben

More information about the Tkinter-discuss mailing list