Python Turtle Cheat Sheet
🐢 Here’s a complete Turtle cheat sheet suitable for both beginners and advanced users – regardless of age. It covers everything: from basic functions through colors, shapes and loops to events, coordinates, animations and complex drawings.
🐢 Python Turtle Cheat Sheet – Complete & In-Depth #
📦 Import Module & Setup #
import turtle
t = turtle.Turtle() # Create turtle
screen = turtle.Screen() # Window object
screen.bgcolor("white") # Background color
t.speed(0) # Speed (0 = fast, 10 = slow)
🧭 Movement & Position #
| Method | Description | Example |
|---|---|---|
forward(x) |
Moves x pixels forward | t.forward(100) |
backward(x) |
Moves x pixels backward | t.backward(50) |
right(angle) |
Turns right (degrees) | t.right(90) |
left(angle) |
Turns left (degrees) | t.left(45) |
goto(x, y) |
Jumps to position (x, y) | t.goto(0, 0) |
setpos(x, y) |
Alias for goto() |
t.setpos(-100, 100) |
setheading(angle) |
Set heading direction (0 = right) | t.setheading(180) |
circle(radius) |
Draws a circle | t.circle(50) |
home() |
Return to start position | t.home() |
position() |
Returns current position | t.position() |
heading() |
Returns current direction | t.heading() |
✏️ Pen Control #
| Method | Description | Example |
|---|---|---|
penup() |
Lift pen (no drawing) | t.penup() |
pendown() |
Put pen down (drawing active) | t.pendown() |
pensize(x) |
Set pen width | t.pensize(3) |
pencolor("color") |
Set pen color | t.pencolor("blue") |
fillcolor("color") |
Set fill color | t.fillcolor("yellow") |
begin_fill() |
Start filling | t.begin_fill() |
end_fill() |
End filling | t.end_fill() |
clear() |
Clear drawing | t.clear() |
reset() |
Reset everything | t.reset() |
write(text) |
Write text | t.write("Hello") |
🐢 Turtle Properties #
| Method | Description | Example |
|---|---|---|
shape("form") |
Shape of turtle ("turtle", "arrow", "circle", "square", "triangle", "classic") |
t.shape("turtle") |
speed(x) |
Speed (0–10, “fastest”) | t.speed("fastest") |
hideturtle() |
Hide turtle | t.hideturtle() |
showturtle() |
Show turtle | t.showturtle() |
window_width() |
Window width | screen.window_width() |
window_height() |
Window height | screen.window_height() |
🎨 Colors #
t.color("red") # Pen color
t.fillcolor("yellow") # Fill color
t.color("blue", "green") # Pen and fill color simultaneously
✅ Supports color names, hex codes ("#FF0000"), RGB tuples ((1, 0, 0))
🔁 Loops & Patterns #
for i in range(36):
t.forward(100)
t.right(170)
✅ Creates a cool spiral pattern
🧮 Coordinates & Geometry #
x, y = t.position()
angle = t.heading()
t.setpos(x + 50, y - 50)
✅ Use position() and heading() for dynamic drawings
🎮 Events & Interactivity #
def turn_left():
t.left(30)
screen.listen()
screen.onkey(turn_left, "Left")
| Event Method | Description |
|---|---|
onkey(func, key) |
React to key press |
onclick(func) |
React to mouse click |
onkeypress(func, key) |
React to pressed key |
listen() |
Activate key recognition |
⏱️ Animation & Timing #
def draw():
t.forward(10)
screen.ontimer(draw, 100)
draw()
✅ Use ontimer() for animations or repeated actions
📦 Multiple Turtles #
t1 = turtle.Turtle()
t2 = turtle.Turtle()
t1.color("blue")
t2.color("green")
✅ You can create and control as many turtles as you want
🧠 Example Project: Star Pattern #
import turtle
t = turtle.Turtle()
t.speed(0)
t.color("purple")
for i in range(100):
t.forward(i * 5)
t.right(144)
turtle.done()
✅ Draws a beautiful star with growing size
🧹 Finishing & Cleanup #
turtle.done() # Keep window open
screen.bye() # Close window
🎓 Summary #
| Category | Most Important Methods/Functions |
|---|---|
| Movement | forward(), backward(), right(), left(), goto() |
| Drawing | penup(), pendown(), begin_fill(), end_fill() |
| Colors | color(), fillcolor(), pencolor() |
| Shapes | shape(), circle(), write() |
| Control | speed(), hideturtle(), showturtle() |
| Events | onkey(), onclick(), listen() |
| Animation | ontimer(), clear(), reset() |