我想使用 Tkinter 将方法绑定到事件,但不需要“bind”方法传递的事件对象。为了清楚起见,一些代码:
from Tkinter import *
root = Tk()
def callback(event):
print 'clicked!'
frame = Frame(root, width=100, height=100)
frame.bind('<Button-1>', callback)
frame.pack()
root.mainloop()
Run Code Online (Sandbox Code Playgroud)
这里,回调中的参数事件是不必要的。是否有任何解决方案或解决方法可以防止绑定方法传递事件对象?
我的意思是,我可以这样称呼:
def callback2():
print 'clicked!'
Run Code Online (Sandbox Code Playgroud)
在绑定中?就像是:
frame.bind('<Button-2>', callback2)
Run Code Online (Sandbox Code Playgroud)
(这实际上不起作用,因为 bin 传递事件,但callback2 不带参数)。