Keyboard Shortcut “Takes 1 positional argument but 2 were given”

后端 未结 1 1108
误落风尘
误落风尘 2020-12-18 15:37

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

相关标签:
1条回答
  • 2020-12-18 15:59

    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:

    ...
    def reset(self, event=None):
        self._game.get_default_score()
        ...
    

    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

    0 讨论(0)
提交回复
热议问题