Python Turtle Cheat Sheet: All Commands with Examples (+ Printable PDF)

This Python Turtle cheat sheet lists 70 commands in 11 groups, each with a one-line example: moving and turning, the pen, colours and fills, shapes, text, clearing, animation and keyboard and mouse events. Every command name and alias was checked against the turtle module, and every example was run in Python 3.12. For the full reference, see the official turtle documentation.

Download the printable Python Turtle cheat sheet (PDF): the same commands on two A4 pages, ready to print.

Python Turtle cheat sheet printable: all turtle commands grouped by setup, movement, pen, colour, shapes, text, events and animation
Preview of the printable cheat sheet.

Minimal Turtle program (starter template)

Every Turtle program follows the same pattern: import the module, create a screen and a turtle, give drawing commands, and finish with turtle.done() so the window stays open:

import turtle

screen = turtle.Screen()
t = turtle.Turtle()

t.forward(100)
t.left(90)
t.forward(100)

turtle.done()

The examples in the tables below assume screen and t were created like this.

Setup and the window

CommandWhat it doesExample
screen = turtle.Screen()Create (or get) the drawing windowscreen = turtle.Screen()
t = turtle.Turtle()Create a turtle to draw witht = turtle.Turtle()
screen.setup(width, height)Window size in pixelsscreen.setup(800, 600)
screen.title(text)Window titlescreen.title("My drawing")
screen.bgcolor(color)Background colourscreen.bgcolor("lightblue")
screen.bgpic(file)Background image (GIF or PNG)screen.bgpic("bg.gif")
screen.screensize(w, h)Size of the drawing area (adds scrollbars if larger than the window)screen.screensize(1200, 900)
screen.window_width()Current window width (window_height() for height)print(screen.window_width())
turtle.done()Keep the window open until you close it; put it lastturtle.done()
screen.exitonclick()Close the window when it is clickedscreen.exitonclick()
screen.bye()Close the window from codescreen.bye()

Move and turn

CommandWhat it doesExample
t.forward(distance)
alias: fd
Move forward, drawing if the pen is downt.forward(100)
t.backward(distance)
alias: bk, back
Move backward without turningt.backward(50)
t.right(angle)
alias: rt
Turn clockwise by angle degreest.right(90)
t.left(angle)
alias: lt
Turn counterclockwiset.left(45)
t.goto(x, y)
alias: setpos, setposition
Move to a point (draws a line if the pen is down)t.goto(100, 50)
t.teleport(x, y)Jump to a point without drawing (Python 3.12+)t.teleport(-100, 0)
t.setx(x) / t.sety(y)
alias: sety
Change only the x or only the y coordinatet.setx(0)
t.setheading(angle)
alias: seth
Point in a direction: 0 east, 90 north, 180 west, 270 southt.setheading(90)
t.home()Back to (0, 0), facing eastt.home()
t.circle(radius, extent, steps)Circle, arc or regular polygon; negative radius goes clockwiset.circle(50, 180)
t.dot(size, color)Filled dot at the current positiont.dot(20, "red")
t.stamp()Print a copy of the turtle shape; returns an idsid = t.stamp()
t.clearstamp(id)
alias: clearstamps
Remove one stamp (clearstamps() removes all)t.clearstamp(sid)
t.undo()Undo the last actiont.undo()
t.speed(speed)1 slowest to 10 fast, 0 = no animation; or "slow", "fast", "fastest"t.speed(0)

Turtle coordinates and headings

The centre of the window is (0, 0). x grows to the right and y grows upwards. Headings are measured counterclockwise from east:

import turtle

screen = turtle.Screen()
screen.setup(700, 520)
screen.title("Turtle coordinates and headings")

t = turtle.Turtle()
t.hideturtle()
t.speed(0)

def jump(x, y):
    t.penup()
    t.goto(x, y)
    t.pendown()

t.color("#bbbbbb")                     # x and y axes
jump(-330, 0); t.goto(330, 0)
jump(0, -240); t.goto(0, 240)

t.color("black")
jump(8, 6)
t.write("(0, 0)", font=("Arial", 12, "normal"))
for x, y in [(200, 150), (-200, 150), (-200, -150), (200, -150)]:
    jump(x, y)
    t.dot(10, "#306998")
    t.write(f"  ({x}, {y})", font=("Arial", 12, "normal"))

arrow = turtle.Turtle(shape="arrow")   # headings
arrow.color("#c62828")
arrow.penup()
arrow.speed(0)
for angle in (0, 90, 180, 270):
    arrow.home()
    arrow.setheading(angle)
    arrow.forward(80)
    arrow.stamp()
    arrow.forward(34)
    arrow.sety(arrow.ycor() - 9)
    arrow.write(f"{angle}", align="center", font=("Arial", 14, "bold"))
arrow.hideturtle()

turtle.done()
Python Turtle coordinates and heading: (0, 0) in the centre, points at plus and minus 200 and 150, and headings 0, 90, 180 and 270 degrees
(0, 0) is the centre; heading 0 points east and 90 points north.

circle(): circles, arcs and polygons

circle() draws around a centre that is radius units to the turtle’s left. extent draws part of the circle and steps turns it into a regular polygon:

import turtle

screen = turtle.Screen()
screen.setup(820, 360)
screen.title("circle() options")

t = turtle.Turtle()
t.speed(0)
t.pensize(3)
t.color("#306998")

examples = [("circle(50)", {"radius": 50}),
            ("circle(50, 180)", {"radius": 50, "extent": 180}),
            ("circle(50, steps=6)", {"radius": 50, "steps": 6}),
            ("circle(-50)", {"radius": -50})]

for i, (text, kwargs) in enumerate(examples):
    x = -285 + i * 190
    t.penup()
    t.goto(x, -40 if kwargs["radius"] > 0 else 60)
    t.setheading(0)
    t.pendown()
    t.circle(**kwargs)
    t.penup()
    t.goto(x, -90)
    t.write(text, align="center", font=("Consolas", 11, "normal"))

t.hideturtle()
turtle.done()
Python Turtle circle options: full circle, half circle with extent 180, hexagon with steps 6 and a clockwise circle with negative radius
Four ways to call circle().

Where is the turtle?

CommandWhat it doesExample
t.position()
alias: pos
Current (x, y)print(t.position())
t.xcor() / t.ycor()
alias: ycor
Current x or y onlyprint(t.xcor(), t.ycor())
t.heading()Current direction in degreesprint(t.heading())
t.towards(x, y)Angle from the turtle to a pointt.setheading(t.towards(0, 100))
t.distance(x, y)Distance to a point (or to another turtle)print(t.distance(0, 0))

Pen

CommandWhat it doesExample
t.pendown()
alias: pd, down
Draw when movingt.pendown()
t.penup()
alias: pu, up
Move without drawingt.penup()
t.pensize(width)
alias: width
Line thicknesst.pensize(5)
t.isdown()True if the pen is downprint(t.isdown())
t.pen(**settings)Set several pen options at oncet.pen(pencolor="red", pensize=3)
import turtle

screen = turtle.Screen()
screen.setup(640, 360)
screen.title("Pen size and colour")

t = turtle.Turtle()
t.speed(0)
t.hideturtle()

colors = ["black", "#306998", "#2e7d32", "#f9a825", "#c62828"]
for i, size in enumerate([1, 3, 6, 10, 16]):
    y = 110 - i * 50
    t.penup()
    t.goto(-280, y)
    t.pendown()
    t.pensize(size)
    t.pencolor(colors[i])
    t.forward(300)
    t.penup()
    t.forward(20)
    t.write(f"pensize({size})", font=("Consolas", 12, "normal"), align="left")
    t.backward(20)

turtle.done()
Python Turtle pensize example: five lines with pen sizes 1, 3, 6, 10 and 16 in different colours
Pen sizes 1 to 16.

Colour and fill

CommandWhat it doesExample
t.color(pen, fill)Set pen and fill colour togethert.color("red", "yellow")
t.pencolor(color)Line and text colour: name, hex or RGBt.pencolor("#306998")
t.fillcolor(color)Colour used by begin_fill()/end_fill()t.fillcolor("gold")
t.begin_fill() ... t.end_fill()
alias: end_fill
Fill the shape drawn between the two callst.begin_fill(); t.circle(40); t.end_fill()
t.filling()True while a fill is in progressprint(t.filling())
screen.colormode(255)Use RGB values 0 to 255 instead of 0 to 1screen.colormode(255); t.pencolor(255, 140, 0)

Colours can be names ("red"), hex strings ("#306998") or RGB tuples. See Python Turtle colors for a full colour chart.

Turtle shape and visibility

CommandWhat it doesExample
t.shape(name)"arrow", "turtle", "circle", "square", "triangle" or "classic"t.shape("turtle")
t.shapesize(w, l, outline)
alias: turtlesize
Stretch the shape: width, length, outlinet.shapesize(2, 3, 1)
t.hideturtle()
alias: ht
Hide the turtle (drawing is faster)t.hideturtle()
t.showturtle()
alias: st
Show it againt.showturtle()
t.isvisible()True if the turtle is shownprint(t.isvisible())
t.tilt(angle)Rotate the shape without changing the headingt.tilt(30)
screen.register_shape(file)
alias: addshape
Use a GIF image as a turtle shapescreen.register_shape("star.gif"); t.shape("star.gif")
screen.getshapes()List the available shape namesprint(screen.getshapes())
import turtle

screen = turtle.Screen()
screen.setup(660, 340)
screen.title("Turtle shapes")

label = turtle.Turtle(visible=False)
label.penup()

names = ["arrow", "turtle", "circle", "square", "triangle", "classic"]
for i, name in enumerate(names):
    x = -250 + i * 100
    t = turtle.Turtle(shape=name)
    t.penup()
    t.color("#306998", "#9ec5ff")
    t.shapesize(2.5)
    t.goto(x, 30)
    label.goto(x, -50)
    label.write(f'"{name}"', align="center", font=("Arial", 13, "normal"))

turtle.done()
Python Turtle shapes list: arrow, turtle, circle, square, triangle and classic shapes side by side
The six built-in turtle shapes.

Text and input

CommandWhat it doesExample
t.write(text, move, align, font)Write text; align "left", "center" or "right"t.write("Hi", align="center", font=("Arial", 16, "bold"))
screen.textinput(title, prompt)Ask the user for text (None if cancelled)name = screen.textinput("Name", "Your name?")
screen.numinput(title, prompt)Ask for a number, with optional default, minval, maxvaln = screen.numinput("Sides", "How many?", 5, 3, 12)

More about fonts and alignment in Python Turtle font.

Clear and reset

CommandWhat it doesExample
t.clear()Erase this turtle's drawings; position and settings stayt.clear()
t.reset()Erase and send the turtle home with default settingst.reset()
screen.reset()
alias: resetscreen
Reset every turtle on the screenscreen.reset()
screen.clear()
alias: clearscreen
Remove all drawings, turtles, background and eventsscreen.clear()

Animation and speed

CommandWhat it doesExample
screen.tracer(0)Stop redrawing after every step (much faster)screen.tracer(0)
screen.update()Redraw the screen once (use with tracer(0))screen.update()
screen.ontimer(function, ms)Call a function after ms millisecondsscreen.ontimer(lambda: t.forward(10), 100)
screen.delay(ms)Pause between screen updatesscreen.delay(0)

For drawings with thousands of lines, call screen.tracer(0) at the start and screen.update() at the end. The whole picture then appears at once instead of line by line, which is often more than 10 times faster than speed(0) alone.

Keyboard and mouse events

CommandWhat it doesExample
screen.listen()Send key presses to the Turtle windowscreen.listen()
screen.onkey(function, key)Run a function when a key is released: "Up", "a", "space"screen.onkey(lambda: t.forward(10), "Up")
screen.onkeypress(function, key)
alias: onkeyrelease
Run while the key is pressed (repeats when held)screen.onkeypress(lambda: t.left(10), "Left")
screen.onclick(function)
alias: onscreenclick
Click anywhere; the function gets x and yscreen.onclick(t.goto)
t.onclick(function)Click on the turtle itselft.onclick(lambda x, y: t.color("red"))
t.ondrag(function)
alias: onrelease
Drag the turtle with the mouset.ondrag(t.goto)

Key events only work after screen.listen(), and the window must have focus. A minimal program that moves the turtle with the arrow keys:

import turtle

screen = turtle.Screen()
t = turtle.Turtle(shape="turtle")

screen.onkeypress(lambda: t.forward(10), "Up")
screen.onkeypress(lambda: t.left(15), "Left")
screen.onkeypress(lambda: t.right(15), "Right")
screen.listen()

turtle.done()

More turtles and saving

CommandWhat it doesExample
t.clone()Copy a turtle with the same position and settingst2 = t.clone()
screen.turtles()List every turtle on the screenprint(len(screen.turtles()))
screen.getcanvas()The Tk canvas, e.g. to save the drawing as EPSscreen.getcanvas().postscript(file="drawing.eps")

postscript() writes an EPS vector file. To convert it to PNG you need Ghostscript installed; alternatively take a screenshot of the window.

Putting it together: a complete example

This program uses commands from most of the tables above: a helper that moves without drawing, a reusable polygon() function, fills, a star and a circle:

import turtle

screen = turtle.Screen()
screen.setup(640, 480)
screen.title("Python Turtle starter")
screen.bgcolor("white")

t = turtle.Turtle()
t.speed(0)
t.pensize(3)

def jump(x, y):
    t.penup()
    t.goto(x, y)
    t.pendown()

def polygon(sides, length, pen, fill):
    t.color(pen, fill)
    t.begin_fill()
    for _ in range(sides):
        t.forward(length)
        t.left(360 / sides)
    t.end_fill()

jump(-260, 50);  polygon(4, 100, "#306998", "#cfe2ff")     # square
jump(-110, 50);  polygon(3, 110, "#2e7d32", "#c8e6c9")     # triangle
jump(60, 50);    polygon(6, 60, "#c62828", "#ffcdd2")      # hexagon

jump(-230, -60)                                            # star
t.color("#f9a825", "#fff176")
t.begin_fill()
for _ in range(5):
    t.forward(120)
    t.right(144)
t.end_fill()

jump(120, -190)                                            # circle
t.color("#6a1b9a", "#e1bee7")
t.begin_fill()
t.circle(55)
t.end_fill()

t.hideturtle()
turtle.done()
Python Turtle example drawing made with cheat sheet commands: filled square, triangle, hexagon, star and circle
The output of the complete example.

Frequently asked questions

What are the basic Python Turtle commands?

forward(), backward(), left(), right(), penup(), pendown(), goto(), color(), begin_fill()/end_fill(), circle() and turtle.done() cover most beginner programs.

How do I move the turtle without drawing?

Call t.penup(), move with goto() or forward(), then t.pendown(). In Python 3.12+ you can also use t.teleport(x, y).

How do I make Turtle draw faster?

Use t.speed(0) and t.hideturtle(). For big drawings, add screen.tracer(0) at the start and screen.update() at the end.

Why does the Turtle window close immediately?

The program ended. Add turtle.done() (or screen.exitonclick()) as the last line.

Is there a printable Python Turtle cheat sheet?

Yes. Download the printable Python Turtle cheat sheet (PDF): two A4 pages with every command from this page.

Next Turtle tutorials to read: