当我在 Tkinter 中调用带有 KeyBind 的方法时,例如parent.bind('<Return>', self.login)
,当它调用self.login
时它似乎添加了第二个变量,就好像它正在调用 self.login(var)
.
虽然有所不同,但当我打印 var
时,它打印 <Tkinter.Event instance at 0x028C5558>
。现在我猜测这要么是调用它的项目,要么是调用它的事件,但是当我让它执行多次时,它显示了相同的事情。
只需添加 var='asdf'
即可解决问题在按键绑定(bind)调用的所有方法中,但这有重要的目的吗?我需要在我的方法中添加一些东西吗?如果不是的话,那它是做什么用的?
最佳答案
非常有用Effbot Tkinter guide ,它指出以下内容(强调我的):
widget.bind(event, handler)
If an event matching the
event
description occurs in the widget, the givenhandler
is called with an object describing the event.
您将其视为 <Tkinter.Event instance at 0x...>
。它具有各种属性,描述发生的情况(例如 x
和 y
鼠标指针的位置、widget
本身等)。
关于python - Tkinter - 使用按键绑定(bind)调用函数会添加变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30034118/