Python turtle set start position

后端 未结 5 2203
长情又很酷
长情又很酷 2020-12-20 03:36

How do I set the startpos (topleft of my turtle square) when starting my code?

And I don\'t mean that it starts from the middle and then goes to that position.

5条回答
  •  盖世英雄少女心
    2020-12-20 03:44

    Python turtle, change start position:

    import turtle
    a = turtle.Turtle()      #instantiate a new turtle object called 'a'
    a.hideturtle()           #make the turtle invisible
    a.penup()                #don't draw when turtle moves
    a.goto(-200, -200)       #move the turtle to a location
    a.showturtle()           #make the turtle visible
    a.pendown()              #draw when the turtle moves
    a.goto(50, 50)           #move the turtle to a new location
    

    The turtle becomes visible and starts drawing at position -200, -200 and goes to 50, 50.

    Here's the documentation on how you can change the turtle's state: https://docs.python.org/2/library/turtle.html#turtle-state

提交回复
热议问题