oval

Ben Bush pythonnew at gmail.com
Sun Dec 4 05:44:36 EST 2005


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:
        print "oval1 got hit!"
    else:
        print "oval2 got hit"
canvas.tag_bind('oval1','<Button>',func=myEvent)
canvas.tag_bind('oval2','<Button>',func=myEvent)
root.mainloop()



More information about the Python-list mailing list