[Python] turtle window automatically closes after opening the python script

Discussão em 'Python' iniciado por Stack, Maio 18, 2025.

  1. Stack

    Stack Membro Participativo

    When i double click on this python script, it automatically closes turtle window after receiving the input.

    import math
    import turtle

    def arc(t, radius, angle):
    arc_length = 2 * math.pi * radius * angle / 360
    n = int(arc_length / 3) + 1
    step_length = arc_length / n
    step_angle = float(angle) / n
    polyline(t, n, step_length, step_angle)

    def polyline(t, n, length, angle):
    for i in range(n):
    t.fd(length)
    t.lt(angle)

    def circle(t, r):
    arc(t, r, 360)
    turtle.mainloop()

    radius=input("Enter the radius of the circle to be printed: ")
    bob=turtle.Turtle()
    circle(bob,radius)


    I have tried running the script from Python IDLE. It's working fine from IDLE. But it closes the turtle window when I double click on the python script file.

    Continue reading...

Compartilhe esta Página