In python, I'm trying to get a game with paddles working similar to Pong. I have this code for moving a paddle within a tkinter canvas.
self.canvas.bind_all("<KeyPress-Left>", self.change_dir)
self.canvas.bind_all("<KeyPress-Right>", self.change_dir)
...
def change_dir(self, e):
if e.keysym == "Left":
self.x = -2
elif e.keysym == "Right":
self.x = 2
self.x is the speed for the paddle that also indicates direction. However, this code results in the user only having to press the key once and then the paddle will change direction. What I want it to do is for the user to have to hold down the key for it to move. There is no way for me to tell it to stop moving. I have an idea, but it doesn't work.
self.canvas.bind_all("<KeyRelease-Right><KeyRelease-Left>", self.change_dir)
Does anyone know how I can check if the Right and Left keys are released at the same time? Thanks!
<KeyRelease-Left>and<KeyRelease-Right>to a callback and setself.x = 0in the callback. - acw1668