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(r oot,width=100,h eight=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','<Butt on>',func=myEve nt)
canvas.tag_bind ('oval2','<Butt on>',func=myEve nt)
root.mainloop()
got hit" if I click the red one. But I always got "oval1 got hit".
from Tkinter import *
root=Tk()
canvas=Canvas(r oot,width=100,h eight=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','<Butt on>',func=myEve nt)
canvas.tag_bind ('oval2','<Butt on>',func=myEve nt)
root.mainloop()
Comment