TypeError: Takes 1 positional argument but two were given
TypeError: Takes 1 positional argument but two were given
所以我正在制作扫雷游戏。但是我得到一个 TypeError:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2800.0_x64__qbz5n2kfra8p0\lib\tkinter\__init__.py", line 1892, in __call__
return self.func(*args)
TypeError: onclick() takes 1 positional argument but 2 were given
但这是我的代码:
class ...:
def __init__(self):
...
def onclick(self):
...
请注意“...”代表“这里有一些代码”。
我已经将 self
作为所有参数,并且 运行 将 __init__
中的函数作为 self.onclick
与事件绑定。为什么 return 出现错误?
我的预期是 onclick()
到 运行。当 onclick
运行 时,它不应该 return 错误。
好的,对不起 mix-up
我昨天查了一下,然后真的把我的头撞在 table 上了。
我用过这个:
def onclick(self):
并且应该这样做:
def onclick(self, event):
再次抱歉没有提前意识到这一点。
所以我正在制作扫雷游戏。但是我得到一个 TypeError:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2800.0_x64__qbz5n2kfra8p0\lib\tkinter\__init__.py", line 1892, in __call__
return self.func(*args)
TypeError: onclick() takes 1 positional argument but 2 were given
但这是我的代码:
class ...:
def __init__(self):
...
def onclick(self):
...
请注意“...”代表“这里有一些代码”。
我已经将 self
作为所有参数,并且 运行 将 __init__
中的函数作为 self.onclick
与事件绑定。为什么 return 出现错误?
我的预期是 onclick()
到 运行。当 onclick
运行 时,它不应该 return 错误。
好的,对不起 mix-up
我昨天查了一下,然后真的把我的头撞在 table 上了。
我用过这个:
def onclick(self):
并且应该这样做:
def onclick(self, event):
再次抱歉没有提前意识到这一点。