Reputation: 23
I get this error every time I click a button using Tkinter. I'm not quite sure what it means that 0 arguments are given, because I thought that callback gives two arguments. Traceback of the error:
Exception in Tkinter callback Traceback (most recent call last):
File "C:\Python27\lib\lib-tk\Tkinter.py", line 1470, in call return self.func(*args)
TypeError: callback() takes exactly 2 arguments (0 given)
Here is all my code related to callback
def callback(input_set, user_set):
user_score = 0
if len(input_set & user_set) == 0:
user_score += len(input_set - user_set) * 2
for multiplier, user_set in enumerate(user_sets, 1):
user_score += len(input_set & user_set) * multiplier
print "Congratulations, you've scored " + str(user_score) + " points!"
# Creates button to calculate score
self.button = Tkinter.Button(self, font="Arial", text="Click to get your score",
width = 45, pady = 5, command = callback)
self.button.grid(column=0, row=3, sticky="", columnspan=2)
Upvotes: 1
Views: 7327
Reputation: 2689
command = callback
here you have to give the args that you are passing to callback. Use command=lambda:callback(arg1,arg2)
where arg1 & arg2 are the arguments that you need to provide the called function
Upvotes: 2
Reputation: 359
In your given function def callback(input_set, user_set):
, It takes two argument, I think when you click button using Tkinter, the two arguments are not passed into the callback function. you have to check that which arguments are passed into the function.
Upvotes: 2