Python Turtle Reference

Turtle Commands Cheat Sheet

Everything you need to draw with Python Turtle — from basic movement to advanced shapes and colors.

Getting started: All examples below assume you've imported turtle at the top of your script. We use import turtle as t so you can type t instead of turtle every time.

Setup & Import

How to bring turtle into your program.

import turtle as t

Import the turtle module and give it the short name t. All commands below will use this alias.

t.speed(n)

Set the drawing speed. 1 = slowest, 10 = fast, 0 = instant (no animation).

e.g. t.speed(6)

Movement

Move the turtle forward, backward, or to a specific spot.

t.forward(distance)

Move forward by the given number of pixels.

e.g. t.forward(100)

t.backward(distance)

Move backward without turning around.

e.g. t.backward(50)

t.goto(x, y)

Move directly to the coordinates (x, y). The center of the screen is (0, 0).

e.g. t.goto(100, -50)

Turning

Change the direction the turtle is facing.

t.right(angle)

Turn clockwise by the given angle in degrees.

e.g. t.right(90) — a square corner

t.left(angle)

Turn counter-clockwise by the given angle in degrees.

e.g. t.left(120) — a triangle corner

t.setheading(angle)

Point the turtle in an absolute direction. 0 = east, 90 = north, 180 = west, 270 = south.

e.g. t.setheading(90) — face up

Pen Control

Control whether the turtle draws as it moves, and how thick the line is.

t.penup()

Lift the pen — the turtle moves without drawing.

t.pendown()

Put the pen back down — the turtle draws as it moves.

t.pensize(width)

Set the thickness of the line in pixels.

e.g. t.pensize(3)

Color & Fill

Change colors and fill in shapes.

t.pencolor('color')

Set the pen (line) color. Use a color name or hex code.

e.g. t.pencolor('orange') or t.pencolor('#23a7f2')

t.fillcolor('color')

Set the fill color for shapes drawn after this.

e.g. t.fillcolor('blue')

t.color('pen', 'fill')

Set both pen and fill color at once.

e.g. t.color('white', 'red')

t.begin_fill()

Start recording the shape to fill. Call this before drawing the shape.

t.end_fill()

Fill in the shape drawn since begin_fill().

Shapes & Stamps

Draw circles and leave stamps on the canvas.

t.circle(radius)

Draw a full circle. Positive radius = counter-clockwise, negative = clockwise.

e.g. t.circle(60)

t.circle(radius, angle)

Draw an arc — only part of a circle, up to the given angle.

e.g. t.circle(80, 180) — a semicircle

t.dot(size, 'color')

Draw a filled dot at the current position.

e.g. t.dot(20, 'red')

t.stamp()

Leave a copy of the turtle shape on the canvas at the current position.

Appearance

Change how the turtle cursor looks, or hide it for cleaner drawings.

t.shape('name')

Change the turtle icon. Options: arrow, turtle, circle, square, triangle, classic.

e.g. t.shape('turtle')

t.hideturtle()

Hide the turtle cursor. Useful once your drawing is complete for a cleaner look.

t.showturtle()

Show the turtle cursor again after hiding it.

Position & State

Check where the turtle is and reset it.

t.position()

Returns the turtle's current (x, y) coordinates as a tuple.

t.heading()

Returns the angle the turtle is currently facing.

t.home()

Move the turtle back to (0, 0) and face east. Draws a line if the pen is down.

t.clear()

Erase everything the turtle has drawn, but keep the turtle where it is.

t.reset()

Erase everything and move the turtle back to (0, 0) with default settings.

Screen

Control the canvas background and window.

t.bgcolor('color')

Set the background color of the canvas.

e.g. t.bgcolor('black')

t.title('text')

Set the window title (only works in desktop Python, not in-browser).

e.g. t.title('My Art')

t.write('text', font=...)

Write text on the canvas at the turtle's current position.

e.g. t.write('Hello!', font=('Arial', 16, 'bold'))

Loops & Patterns

Combine turtle commands with loops to create awesome patterns.

for i in range(4):
    t.forward(100)
    t.right(90)

Draw a square — repeat 4 times: go forward, turn 90 degrees.

for i in range(3):
    t.forward(100)
    t.left(120)

Draw a triangle — repeat 3 times: go forward, turn 120 degrees.

for i in range(36):
    t.circle(50)
    t.right(10)

Draw a spirograph flower — draw a circle, rotate slightly, repeat.

colors = ['red', 'blue', 'green']
for c in colors:
    t.pencolor(c)
    t.circle(40)
    t.right(120)

Loop through a list of colors — each circle gets a different color.

for i in range(100):
    t.forward(i * 2)
    t.right(91)

Draw a growing spiral — each step gets longer, creating an expanding pattern.

t.fillcolor('gold')
t.begin_fill()
for i in range(5):
    t.forward(100)
    t.right(144)
t.end_fill()

Draw a filled star — the 144-degree turn creates a five-pointed star shape.

Ready to try these out?

Open the Hackingtons Turtle Editor and start drawing.

Open Turtle Editor