So I'm making a minesweeper game. But I get a 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
But here's my code:
class ...:
def __init__(self):
...
def onclick(self):
...
Please observe that "..." represents "some code here".
I already have self
as an argument in everything, and am running the function in __init__
as self.onclick
with an event binding. Why is it returning an error?
I was expecting onclick()
to run like expected. When onclick
runs it should not return a error.
CodePudding user response:
Ok sorry for the mix-up
I looked it up yesterday- and literally smacked my head on the table.
I used this:
def onclick(self):
And should have done this:
def onclick(self, event):
Again, I'm sorry for not realizing this in advance.
CodePudding user response:
as far as I see from the error output you call the onclick function with "**kwargs" which means you're calling your function with an arbitrary number of keyword arguments.
if you want to accomplish that you should edit your function like that:
def onclick(self, *args, **kwargs):
...
here's more information about that: link