Turtle Position
Coordinates
Every point in the turtle window has a position, written as (x, y):
xtells how far to the right of the middle the point is. Negative values are to the left.ytells how far above the middle the point is. Negative values are below.
The middle of the window is (0, 0). This is where the turtle starts.
Go to a Position
Use goto(x, y) to move the turtle straight to a position:
Example
Move the turtle to (100, 50):
import turtle
t = turtle.Turtle()
t.goto(100, 50)
turtle.done()
Result:
The pen is down, so the turtle draws a line on its way.
With three goto() calls, you can draw a triangle:
Example
Draw a triangle with goto():
import turtle
t = turtle.Turtle()
t.goto(100, 0)
t.goto(50, 100)
t.goto(0, 0)
turtle.done()
Result:
goto() does not turn the turtle. In the picture, the turtle still faces right.
Start Somewhere Else
On the previous page, you learned about penup() and pendown().
To start a drawing somewhere other than the middle, lift the pen, go to the new position, and put the pen down again:
Example
Draw a line in the upper half of the window:
import turtle
t = turtle.Turtle()
t.penup()
t.goto(-100, 50)
t.pendown()
t.forward(200)
turtle.done()
Result:
Turn to a Direction
left() and right() turn the turtle from the direction it is facing now.
Use setheading() to make the turtle face an exact direction, no matter which way it faces now:
Example
Face up, then move forward:
import turtle
t = turtle.Turtle()
t.setheading(90)
t.forward(100)
turtle.done()
Result:
Go Home
Use home() to move the turtle back to (0, 0), facing right, just like when it started:
Example
Draw two lines, then go home:
import turtle
t = turtle.Turtle()
t.forward(100)
t.left(90)
t.forward(50)
t.home()
turtle.done()
Result:
The pen is down, so the turtle draws a line on its way home.
Get the Position
Use position() to find out where the turtle is:
Example
Print the position of the turtle:
import turtle
t = turtle.Turtle()
t.forward(100)
t.left(90)
t.forward(50)
print(t.position())
turtle.done()
Result:
(100.00,50.00)
Run Example »
The turtle moved 100 pixels to the right and 50 pixels up, so it is at (100, 50).