How Do I Bind To A Function Inside A Class And Still Use The Event Variable?
class Player(): def __init__(): ... def moveHandle(self, event): self.anything = ... box.bind('', Player.moveHandle) The bind function sets self
Solution 1:
the problem is that you are trying to use an instance method as a class method.
consider the following:classPlayer():def__init__():
...
defmoveHandle(self, event):
self.anything = ...
box.bind("<Key>", Player.moveHandle)
where box
is an instance of something, but Player
is not.
instead this:
classPlayer():def__init__(self):
...
defmoveHandle(self, event):
self.anything = ...
p = Player()
box.bind("<Key>", p.moveHandle)
creates an instance of the player class, and then binds to the instances method, not the class method.
Post a Comment for "How Do I Bind To A Function Inside A Class And Still Use The Event Variable?"