Trying to make a keyboard shortcut to reset a game. Earlier in the __init__ class I create a menu to start a new game, and use self.reset to reset the score/grid etc. I now have been trying to implement the shortcut with the same command - the reset being a method within the class.
self._master.bind_all('<Control-n>', self.reset)
This is the error:
TypeError: reset() takes 1 positional argument but 2 were given
My confusion is that the self.reset works fine earlier in the __init__ but then does not work for the shortcut?
I do not see how the shortcut is even giving any positional arguments to the method.
Now if I change it to self.reset() I get an error about the current class missing the _game attribute.
Here is the reset method:
def reset(self):
self._game.get_default_score()
self._game.reset()
self._grid_view.draw(self._game.grid, self._game.find_connections())
That is easy - whatever the mechanism that binds the shortcut does, it is passing an extra parameter to your
reset
method.Since you don't care what it is at all, just declare your method to accept an extra optional parameter, and you should be good:
So, searching for "bind_all" we find out your code actually uses tkinter, and what tkinter passe along to your method is the "event" - an object with information on what key whas actually pressed and such - http://effbot.org/tkinterbook/tkinter-events-and-bindings.htm