如何将 Enter 键绑定到 Tkinter 中的按钮 [英] How to bind the Enter key to a button in Tkinter
本文介绍了如何将 Enter 键绑定到 Tkinter 中的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个按钮:
button3 = Button(app, text="Show Members", width=15, command=lambda: showLDAPMembers(yourName,yourPassword))
如何将 ENTER 键绑定到它?我试着做:
How do I bind the ENTER key to it? I tried doing:
app.bind('<Return>', showLDAPMembers(yourName,yourPassword))
但我得到未解决的参考错误..
but I get unresolved reference error..
def showLDAPMembers(yourName,yourPassword):
app.lb.delete(0,END)
推荐答案
如果要传递参数,则需要使用 lambda.
You need to use a lambda if you're passing arguments.
app.bind("<Return>", lambda x: showLDAPMembers(yourName,yourPassword))
bind
命令会自动返回调用它的事件,因此您需要定义并丢弃它(使用 lambda x:
)
The bind
command automatically returns the event that called it, so you need to define and throw away that (with lambda x:
)
这篇关于如何将 Enter 键绑定到 Tkinter 中的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文