我见过像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)
win是窗口的名称
以下是错误消息:
Exception in Tkinter callback
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/tkinter/__init__.py", line 1705, in __call__
return self.func(*args)
TypeError: check_guess() takes 1 positional argument but 2 were given
下面是check_guess的代码:
def check_guess(self):
print("hello")
global guesses
global correctguesses
global word2
将键绑定到函数激活时,您正在添加多个参数
当你定义“检查猜测”时
而不是
def check_guess(self):
尝试:
*args几乎允许通过一个函数传递多个参数
相关问题 更多 >
编程相关推荐