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.
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
| Command | What it does | Example |
|---|---|---|
screen = turtle.Screen() | Create (or get) the drawing window | screen = turtle.Screen() |
t = turtle.Turtle() | Create a turtle to draw with | t = turtle.Turtle() |
screen.setup(width, height) | Window size in pixels | screen.setup(800, 600) |
screen.title(text) | Window title | screen.title("My drawing") |
screen.bgcolor(color) | Background colour | screen.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 last | turtle.done() |
screen.exitonclick() | Close the window when it is clicked | screen.exitonclick() |
screen.bye() | Close the window from code | screen.bye() |
Move and turn
| Command | What it does | Example |
|---|---|---|
t.forward(distance)alias: fd | Move forward, drawing if the pen is down | t.forward(100) |
t.backward(distance)alias: bk, back | Move backward without turning | t.backward(50) |
t.right(angle)alias: rt | Turn clockwise by angle degrees | t.right(90) |
t.left(angle)alias: lt | Turn counterclockwise | t.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 coordinate | t.setx(0) |
t.setheading(angle)alias: seth | Point in a direction: 0 east, 90 north, 180 west, 270 south | t.setheading(90) |
t.home() | Back to (0, 0), facing east | t.home() |
t.circle(radius, extent, steps) | Circle, arc or regular polygon; negative radius goes clockwise | t.circle(50, 180) |
t.dot(size, color) | Filled dot at the current position | t.dot(20, "red") |
t.stamp() | Print a copy of the turtle shape; returns an id | sid = t.stamp() |
t.clearstamp(id)alias: clearstamps | Remove one stamp (clearstamps() removes all) | t.clearstamp(sid) |
t.undo() | Undo the last action | t.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()
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()
Where is the turtle?
| Command | What it does | Example |
|---|---|---|
t.position()alias: pos | Current (x, y) | print(t.position()) |
t.xcor() / t.ycor()alias: ycor | Current x or y only | print(t.xcor(), t.ycor()) |
t.heading() | Current direction in degrees | print(t.heading()) |
t.towards(x, y) | Angle from the turtle to a point | t.setheading(t.towards(0, 100)) |
t.distance(x, y) | Distance to a point (or to another turtle) | print(t.distance(0, 0)) |
Pen
| Command | What it does | Example |
|---|---|---|
t.pendown()alias: pd, down | Draw when moving | t.pendown() |
t.penup()alias: pu, up | Move without drawing | t.penup() |
t.pensize(width)alias: width | Line thickness | t.pensize(5) |
t.isdown() | True if the pen is down | print(t.isdown()) |
t.pen(**settings) | Set several pen options at once | t.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()
Colour and fill
| Command | What it does | Example |
|---|---|---|
t.color(pen, fill) | Set pen and fill colour together | t.color("red", "yellow") |
t.pencolor(color) | Line and text colour: name, hex or RGB | t.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 calls | t.begin_fill(); t.circle(40); t.end_fill() |
t.filling() | True while a fill is in progress | print(t.filling()) |
screen.colormode(255) | Use RGB values 0 to 255 instead of 0 to 1 | screen.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
| Command | What it does | Example |
|---|---|---|
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, outline | t.shapesize(2, 3, 1) |
t.hideturtle()alias: ht | Hide the turtle (drawing is faster) | t.hideturtle() |
t.showturtle()alias: st | Show it again | t.showturtle() |
t.isvisible() | True if the turtle is shown | print(t.isvisible()) |
t.tilt(angle) | Rotate the shape without changing the heading | t.tilt(30) |
screen.register_shape(file)alias: addshape | Use a GIF image as a turtle shape | screen.register_shape("star.gif"); t.shape("star.gif") |
screen.getshapes() | List the available shape names | print(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()
Text and input
| Command | What it does | Example |
|---|---|---|
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, maxval | n = screen.numinput("Sides", "How many?", 5, 3, 12) |
More about fonts and alignment in Python Turtle font.
Clear and reset
| Command | What it does | Example |
|---|---|---|
t.clear() | Erase this turtle's drawings; position and settings stay | t.clear() |
t.reset() | Erase and send the turtle home with default settings | t.reset() |
screen.reset()alias: resetscreen | Reset every turtle on the screen | screen.reset() |
screen.clear()alias: clearscreen | Remove all drawings, turtles, background and events | screen.clear() |
Animation and speed
| Command | What it does | Example |
|---|---|---|
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 milliseconds | screen.ontimer(lambda: t.forward(10), 100) |
screen.delay(ms) | Pause between screen updates | screen.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
| Command | What it does | Example |
|---|---|---|
screen.listen() | Send key presses to the Turtle window | screen.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 y | screen.onclick(t.goto) |
t.onclick(function) | Click on the turtle itself | t.onclick(lambda x, y: t.color("red")) |
t.ondrag(function)alias: onrelease | Drag the turtle with the mouse | t.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
| Command | What it does | Example |
|---|---|---|
t.clone() | Copy a turtle with the same position and settings | t2 = t.clone() |
screen.turtles() | List every turtle on the screen | print(len(screen.turtles())) |
screen.getcanvas() | The Tk canvas, e.g. to save the drawing as EPS | screen.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()
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:
Bijay Kumar is a 13-time Microsoft MVP with more than 18 years in software development, and the founder of Python Guides and TSinfo Technologies. He started out building .NET and SharePoint solutions at HP, TCS and KPIT before moving into Python, machine learning and AI, and he also builds web apps with TypeScript and React. He writes the tutorials here himself, and every example is run before publishing so you see the real output. More about Bijay · Microsoft MVP profile · LinkedIn