[Python] Making multiple turtles in one window

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

  1. Stack

    Stack Membro Participativo

    I want to make more than two turtles when I run the modules. So I declared two variables on turtle but there's only one turtle I can see. What's wrong with my code?

    import turtle
    t1=turtle.Turtle()
    t2=turtle.Turtle()

    colors = ["red", "blue", "green"]
    turtle.bgcolor("yellow")
    t1.speed(3)
    t1.width(5)
    length1 = 10
    t2.speed(3)
    t2.width(5)
    length2 = 10

    while length1 < 500:
    t1.fd(length1)
    t1.pencolor(colors[length1%3])
    t1.right (89)
    length1 += 3 #length1 = length1 + 3

    while length2 < 500:
    t2.fd(length2)
    t2.pencolor(pink)
    t2.left (89)
    length2 += 4 #length2 = length2 + 4

    input()

    Continue reading...

Compartilhe esta Página