Skip to content Skip to sidebar Skip to footer

Python/tkinter Event Argument Issue

my code seems to run fine with the brown square appearing in the blank window until I try and press one of the keys, when I do that nothing happens apart from an error message appe

Solution 1:

When calling to function inside an object, self (the instance of the object) is sent as a first argument. You can undo that with some methods, staticmethod as the most common one, but that is not what you look for in that case.

The error you get indicates the interpreter sent this self parameter and the regular event parameter, but your method gets only one parameter, and can not handle them.

Make sure all your functions gets self (or any name you choose like inst) as a first parameter in addition to the other parameters:

def on_keyrelease(self, event):

Same goes for move and on_keypress.


Post a Comment for "Python/tkinter Event Argument Issue"