[Python] Turtle pauses when I try to turn it

Discussão em 'Python' iniciado por Stack, Setembro 14, 2025.

  1. Stack

    Stack Membro Participativo

    Here is my code:

    from turtle import Turtle, Screen
    import time
    import random

    def check_wall_collision():
    if ball.xcor() > (window.window_width() / 2) - 20 or ball.xcor() < -(window.window_width() / 2) + 20:
    ball.left(180)
    elif ball.ycor() > (window.window_height() / 2) - 20 or ball.ycor() < -(window.window_height() / 2) + 20:
    ball.left(180)



    window = Screen()


    ball = Turtle(shape='circle')


    while True:
    ball.forward(7)
    check_wall_collision()


    window.mainloop()


    This code basically makes a ball go forward until it collides into the edge of the screen, when it collides with the edge of the screen, it turns 180 degrees. The problem is though, when the ball collides with the wall, it pauses for a second or two before turning.

    Continue reading...

Compartilhe esta Página