Python 如何将命令绑定到Tkinter中的enter键?

Python 如何将命令绑定到Tkinter中的enter键?,python,tkinter,Python,Tkinter,我见过像bind命令这样的解决方案,但当我给它参数(“”,self.checkguess)时,它会出错,说需要一个参数 self.input = Entry(self.win) self.input.place(x = 0, y = 80) self.input.focus_set() self.attempt = Button(self.win, text = "Guess", width = 6, height = 2, command = self.check_guess) self.at

我见过像bind命令这样的解决方案,但当我给它参数(“”,self.checkguess)时,它会出错,说需要一个参数

self.input = Entry(self.win)
self.input.place(x = 0, y = 80)
self.input.focus_set()
self.attempt = Button(self.win, text = "Guess", width = 6, height = 2, command = self.check_guess)
self.attempt.place(x = 0, y = 120)
self.win.bind('<Return>', self.check_guess)
下面是check_guess的代码:

def check_guess(self):
        print("hello")
        global guesses
        global correctguesses
        global word2

将键绑定到函数激活时,您正在添加多个参数

当你定义“检查猜测”时

而不是
def check\u guess(self):

尝试:


*args几乎允许通过一个函数传递多个参数

好吧,我想我可能做错了什么。另外,为了澄清,check\u guess与添加的代码在同一个类中。回调方法应接受另一个参数,即事件对象
def check\u guess(self,event):
。。。
def check_guess(self):
        print("hello")
        global guesses
        global correctguesses
        global word2
def check_guess(*args):