如何将Enter键绑定到Tkinter中的按钮

cod*_*ail 1 python tkinter

我有一个按钮:

button3 = Button(app, text="Show Members", width=15, command=lambda: showLDAPMembers(yourName,yourPassword))
Run Code Online (Sandbox Code Playgroud)

如何将ENTER键绑定到它?我试过做:

app.bind('<Return>', showLDAPMembers(yourName,yourPassword))
Run Code Online (Sandbox Code Playgroud)

但是我得到了未解决的参考错误..

def showLDAPMembers(yourName,yourPassword):
    app.lb.delete(0,END)
Run Code Online (Sandbox Code Playgroud)

Ada*_*ith 6

如果你传递参数,你需要使用lambda.

app.bind("<Return>", lambda x: showLDAPMembers(yourName,yourPassword))
Run Code Online (Sandbox Code Playgroud)

bind命令自动返回调用它的事件,因此您需要定义并丢弃(带lambda x:)