oval

Diez B. Roggisch deets at nospam.web.de
Sun Dec 4 06:45:24 EST 2005


Ben Bush wrote:
> I tested the following code and wanted to get the message of "oval2
> got hit" if I click the red one. But I always got "oval1 got hit".
> from Tkinter import *
> root=Tk()
> canvas=Canvas(root,width=100,height=100)
> canvas.pack()
> a=canvas.create_oval(10,10,20,20,tags='oval1',fill='blue')
> b=canvas.create_oval(50,50,80,80,tags='oval2',fill='red')
> def myEvent(event):
>     if a:

Here is your problem. a is a name, bound to some value. So - it is true, 
as python semantics are that way. It would not be true if it was e.g.

False, [], {}, None, ""


What you want instead is something like

if event.source == a:
     ...

Please note that I don't know what event actually looks like in Tkinter, 
so check the docs what actually gets passed to you.


Regards,

Diez



More information about the Python-list mailing list