In my program, I am trying to find if a certain variable is in a list. However, I keep getting the following error and I am very stuck on how to get past it:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\mikey\AppData\Local\Programs\Python\Python38\lib\tkinter\__init__.py", line 1883, in __call__
return self.func(*args)
File "G:\My Drive\DGT301\Python\AS\order.py", line 171, in confirm_order
self.check(self.order_item, self.food_list)
TypeError: check() missing 1 required positional argument: 'self'
Here is my code:
def find(thing, list3d):
for x in list3d:
for y in x:
if y[1] == thing:
return True
return False
def check(item, list3d, result, self):
self.result = 'found' if self.find(item, list3d) else 'not found'
print(f'{item} was {result}')
def confirm_order(self):
self.order_item = self.r.get()
self.check(self.order_item, self.food_list)
I tried putting "self." before all the variables and tried removing some and the error stays the same.
When you call a method on an object, the Python interpreter will automatically insert a reference to that object as the first positional argument. To handle this, the first argument for a method (a function defined inside a class) conventionally calls the first argument
self
. Your functions are not defined inside of a class, so the use ofself
doesn't make sense.