More Turtle Commands Jump to this section

This lesson introduces a few handy turtle commands you can use to control visibility, position, and appearance: hideturtle(), showturtle(), goto() (alias setposition()), shape(), stamp(), and helpers like position() and setheading().

hideturtle() and showturtle() Jump to this section

Use hideturtle() to hide the turtle icon (so only the drawing shows), and showturtle() to make it visible again.

import turtle

t = turtle.Turtle()
t.forward(80)
t.hideturtle()   # hide the turtle cursor
t.forward(40)    # the turtle draws but you don't see the cursor
t.showturtle()   # show cursor again

Hiding the turtle is useful when you want a clean drawing without the arrow visible.

goto(x, y) / setposition(x, y) Jump to this section

goto(x, y) (same as setposition(x, y)) moves the turtle to the specified coordinates. Use penup() before moving if you do not want a line drawn.

import turtle

t = turtle.Turtle()
t.penup()
t.goto(100, 50)   # jump to (100, 50) without drawing
t.pendown()
t.circle(30)

Coordinates: the canvas center is (0, 0), right is positive x, up is positive y.

position() and setheading() Jump to this section

position() returns the current (x, y) position. setheading(angle) sets the direction the turtle faces (0 = right, 90 = up).

import turtle

t = turtle.Turtle()
t.forward(60)
pos = t.position()
print('Current position:', pos)
t.setheading(90)  # point up
t.forward(40)

position() is handy for debugging or saving where you are before moving.

shape(name) Jump to this section

Change the turtle icon with shape(...). Common shapes include 'arrow', 'turtle', 'circle', 'square', 'triangle'.

import turtle

t = turtle.Turtle()
t.shape('turtle')
t.forward(80)

Using a different shape can make interactive programs easier to read (for example, using 'circle' for a ball).

stamp() Jump to this section

stamp() leaves a copy of the turtle's shape at the current position. Useful for marking points.

import turtle

t = turtle.Turtle()
for i in range(5):
    t.forward(40)
    t.stamp()   # leave an imprint of the turtle

stamp() can build patterns without drawing lines between stamps.

Putting it together: simple demo Jump to this section

import turtle

screen = turtle.Screen()
t = turtle.Turtle()
t.shape('turtle')
t.speed(2)

# move without drawing, stamp a few positions, then draw between them
t.penup()
t.goto(-80, 0); t.stamp()
t.goto(-40, 40); t.stamp()
t.goto(0, 0); t.stamp()
t.goto(40, -40); t.stamp()
t.pendown()
t.showturtle()
t.goto(60, 0)

That's a set of useful commands you can mix with what you've learned earlier (movement, pen control, and loops) to make more interesting drawings and simple interactive sketches.