from Tkinter import *
master = Tk()
def oval_mouse_click(event):
print "in oval"
def canvas_mouse_click(event):
print "in canvas"
w = Canvas(master, width = 800, height = 600)
uid = w.create_oval(390, 290, 410, 310, fill='blue')
w.tag_bind(uid, "<Button-1>", lambda x: oval_mouse_click(x))
w.bind("<Button-1>" , canvas_mouse_click)
w.pack()
mainloop()
一些代码,当我在控制台上单击画布我有“帆布”的消息。 当我点击]椭圆形我有两条消息“椭圆形”和“画布”,但我想只有第一条消息。有什么办法可以阻止事件发生?
我可以用一些全球性的标志来完成这项任务,但我认为Tkl应该有更自然的方式。
您发现最简单的方法了''return'break''不适用于画布标签绑定。 – mmgp
相关:[Python tkinter:在文本小部件标签中停止事件传播](http://stackoverflow.com/questions/13066773/python-tkinter-stopping-event-propagation-in-text-widgets-tags/13076458) – phoibos