Aug-28-2021, 04:12 PM
Hi, I am following a tutorial online: freecodecamp.org on Youtube. I am learning how to program a simple pong game in Python. However, when I go and execute my code the "left paddle" associated with the "w" key on my keyboard doesn't respond. My code looks the same as the guy in the tutorial video, and I don't know why my code doesn't work. I believe it's my wn.listen() method, but I'm not sure. Any help or suggestions would be greatly appreciated.
import turtle wn = turtle.Screen() wn.title("Pong by @TokyoEdTech") wn.bgcolor("black") wn.setup(width=800, height=600) wn.tracer(0) # Paddle A paddle_a = turtle.Turtle() paddle_a.speed(0) paddle_a.shape("square") paddle_a.color("white") paddle_a.shapesize(stretch_wid=5, stretch_len=1) paddle_a.penup() paddle_a.goto(-350, 0) # Paddle B paddle_a = turtle.Turtle() paddle_a.speed(0) paddle_a.shape("square") paddle_a.color("white") paddle_a.shapesize(stretch_wid=5, stretch_len=1) paddle_a.penup() paddle_a.goto(350, 0) # Ball ball = turtle.Turtle() ball.speed(0) ball.shape("square") ball.color("white") ball.penup() ball.goto(0, 0) # Function def paddle_a_up(): y = paddle_a.ycor() y += 20 paddle_a.sety(y) # Keyboard binding wn.listen() wn.onkeypress(paddle_a_up(), "w") # this calls the function paddle_a_up() # Main game loop while True: wn.update()