[Python] Draw a square in Python Turtle

Discussão em 'Python' iniciado por Stack, Fevereiro 25, 2025.

  1. Stack

    Stack Membro Participativo

    I am following a tutorial for Python learning and I can't get the screen to open to draw. I don't get an error, it just shows that the program finish running. Maybe I missed something, can someone point it out?

    import turtle #acutally called turtle to draw a turtle beautiful also used
    to draw other stuff

    # to draw a square or eventually a turtle you need to do this things below
    # to draw a square you want to : move forward,turn right,move forward,turn
    right,move forward turn right
    def draw_square(): #draw square for turtles
    window = turtle.Screen() #this is the background where the turtle will
    move
    window.bgcolor("red") # the color of the screen
    brad = turtle.Turtle() #this is how to start drawing like time.sleep you use turtle.Turtle
    brad.forward(100)#move turtle forward takes in a number which is the distance to move forward
    brad.forward(90)# moves right
    brad.forward(100)
    brad.forward(90)
    brad.forward(100)
    brad.forward(90)
    brad.forward(100)
    brad.forward(90)
    window.exitonclick() #click the screen to close it
    draw_square()

    Continue reading...

Compartilhe esta Página