[Python] Turtle not detecting key presses in Python

Discussão em 'Python' iniciado por Stack, Julho 22, 2025.

  1. Stack

    Stack Membro Participativo

    Here is a HUGELY simplified version of my code:

    from turtle import Turtle, Screen
    import time

    speed_x = 20
    speed_y = 29

    def move_right():
    print('exectuted')
    def game_loop():
    ball.goto(ball.xcor() + speed_x, ball.ycor() + speed_y)

    window.update()

    window.ontimer(game_loop, 1)


    window = Screen()
    time.sleep(2)

    ball = Turtle(shape='circle')
    ball.color('white')


    paddle = Turtle(shape='square')

    window.onkeypress(move_right, 'Right')
    window.onkeypress(move_right, 'D')

    game_loop()

    window.mainloop()


    I expected the move_right() function to execute (which for testing should have printed out something)

    But I get nothing

    Continue reading...

Compartilhe esta Página