Last modified: Jan 30, 2026 By Alexander Williams

Python Turtle API Guide for Graphics

The Python Turtle API is a classic library. It provides a fun way to learn programming. You control a virtual "turtle" with a pen. It draws lines on a screen as it moves.

It is perfect for beginners. It introduces core programming concepts visually. This guide will teach you how to use it. You will learn to create shapes and animations.

What is the Turtle API?

The Turtle API is part of Python's standard library. It is based on the Logo programming language. The turtle is a cursor on a canvas. You command it to move, turn, and draw.

It is a powerful educational tool. It makes abstract code concepts tangible. You see the results of your commands immediately. This visual feedback is great for learning.

While Turtle is for graphics, other APIs connect to web services. For that, see our Python API Calls Guide for Beginners.

Getting Started with Turtle

You don't need to install anything. Turtle comes with Python. Just import the module to begin.


# Import the turtle module
import turtle

# Create a screen/window for drawing
screen = turtle.Screen()
screen.title("My Turtle Drawing")

# Create a turtle object
my_turtle = turtle.Turtle()
my_turtle.shape("turtle")  # Make it look like a turtle

# Your drawing commands will go here

# Keep the window open
turtle.done()
    

This code opens a graphics window. It creates a turtle object named my_turtle. The window stays open until you close it.

Basic Turtle Commands

Let's explore the fundamental commands. These control the turtle's movement and pen.

Moving the Turtle

The turtle moves in units called pixels. Use forward() and backward().


import turtle

t = turtle.Turtle()
t.forward(100)  # Move forward 100 pixels
t.backward(50)  # Move backward 50 pixels
turtle.done()
    

Turning the Turtle

Change direction with right() and left(). The angle is in degrees.


import turtle

t = turtle.Turtle()
t.forward(100)
t.right(90)     # Turn right 90 degrees
t.forward(100)
t.left(45)      # Turn left 45 degrees
t.forward(70)
turtle.done()
    

Controlling the Pen

The pen draws a line by default. You can lift it or change its color.

Use penup() to move without drawing. Use pendown() to start drawing again. Use pencolor() to set the line color.


import turtle

t = turtle.Turtle()
t.pencolor("blue")
t.forward(50)
t.penup()       # Lift the pen
t.forward(50)
t.pendown()     # Put the pen down
t.pencolor("red")
t.forward(50)
turtle.done()
    

Drawing Your First Shapes

Let's combine commands to draw shapes. We'll start with a square and a circle.

Drawing a Square

A square has four equal sides. You move forward and turn right four times.


import turtle

t = turtle.Turtle()
t.pensize(3)  # Make the line thicker

for _ in range(4):  # Repeat 4 times
    t.forward(100)
    t.right(90)

turtle.done()
    

Drawing a Circle

The circle() method makes this easy. It draws a circle with a given radius.


import turtle

t = turtle.Turtle()
t.pencolor("green")
t.circle(50)  # Draw a circle with radius 50

turtle.done()
    

More Advanced Techniques

You can create complex drawings. Use loops, functions, and event listening.

Using Loops for Patterns

Loops help create repetitive patterns. This draws a star shape.


import turtle

t = turtle.Turtle()
t.speed("fastest")  # Set drawing speed to maximum
t.pencolor("purple")

for i in range(36):  # Repeat 36 times
    t.forward(200)
    t.right(170)     # This angle creates a star pattern

turtle.done()
    

Filling Shapes with Color

Use begin_fill() and end_fill(). Set the fill color with fillcolor().


import turtle

t = turtle.Turtle()
t.fillcolor("orange")
t.pencolor("black")

t.begin_fill()
for _ in range(3):  # Draw a triangle
    t.forward(100)
    t.left(120)
t.end_fill()

turtle.done()
    

Practical Example: A Simple Scene

Let's draw a simple scene with a house. This combines multiple techniques.


import turtle

# Setup
screen = turtle.Screen()
screen.bgcolor("lightblue")
artist = turtle.Turtle()
artist.speed(5)

# Draw a square for the house base
artist.penup()
artist.goto(-50, -100)
artist.pendown()
artist.fillcolor("yellow")
artist.begin_fill()
for _ in range(4):
    artist.forward(100)
    artist.left(90)
artist.end_fill()

# Draw a triangle for the roof
artist.penup()
artist.goto(-60, 0)
artist.pendown()
artist.fillcolor("brown")
artist.begin_fill()
artist.goto(0, 60)
artist.goto(60, 0)
artist.goto(-60, 0)
artist.end_fill()

# Draw a door
artist.penup()
artist.goto(-15, -100)
artist.pendown()
artist.fillcolor("red")
artist.begin_fill()
for _ in range(2):
    artist.forward(30)
    artist.left(90)
    artist.forward(50)
    artist.left(90)
artist.end_fill()

artist.hideturtle()  # Hide the turtle cursor
turtle.done()
    

Common Challenges and Tips

Beginners often face a few common issues. Here are solutions.

The window closes immediately. Always end your script with turtle.done() or turtle.mainloop(). This keeps the window open.

Drawing is too slow. Use turtle.speed() to adjust. Set it to "fastest" for instant drawing.

Managing complex projects. For larger graphics projects, consider a more advanced tool like the