turtle

The Python turtle module provides tools to create pictures and shapes by controlling a turtle that draws on a canvas. This module is ideal for learning programming concepts in a fun and engaging manner.

Here’s a quick example:

Python
>>> import turtle

>>> # Move the turtle forward by 100 units
>>> turtle.forward(100)

>>> # Turn the turtle right by 90 degrees
>>> turtle.right(90)

Running the code snippet above results in the following output:

Python turtle module example screenshot

Key Features

  • Provides a visual way to learn programming
  • Supports creating complex shapes and patterns
  • Offers control over turtle’s movement and drawing attributes
  • Includes event handling for interactive programs
  • Supports multiple turtles on the same screen for complex drawings
  • Enables customization of colors, pen size, and speed
  • Is cross-platform

Frequently Used Classes and Functions

Object Type Description
turtle.Turtle Class Represents a turtle graphics pen
turtle.Screen Class Represents the window for turtle graphics
turtle.forward() Function Moves the turtle forward by a specified distance
turtle.right() Function Turns the turtle clockwise by a specified angle
turtle.done() Function Signals the program to complete and close the window
turtle.left() Function Turns the turtle counterclockwise by a specified angle

Examples

Draw a square using a loop:

Python
>>> import turtle

>>> for _ in range(4):
...     turtle.forward(100)
...     turtle.right(90)
...

Draw a circle:

Python
>>> turtle.circle(50)

Draw a triangle:

Python
>>> for _ in range(3):
...     turtle.forward(100)
...     turtle.left(120)
...

Common Use Cases

  • Creating basic drawings and shapes
  • Teaching programming concepts through visualization
  • Developing interactive programs using turtle graphics
  • Demonstrating loops, functions, and event handling visually
  • Prototyping geometric patterns and designs
  • Creating fun projects for educational purposes

Real-World Example

Here’s an example of drawing a star shape using the turtle module:

Python
>>> import turtle
>>> star = turtle.Turtle()

>>> for _ in range(5):
...     star.forward(100)
...     star.right(144)
...

>>> turtle.done()

In this example, you draw a star by moving forward and turning right in a loop. The turtle.done() function indicates that the drawing is complete and keeps the window open.

Tutorial

The Beginner's Guide to Python Turtle

In this step-by-step tutorial, you'll learn the basics of Python programming with the help of a simple and interactive Python library called turtle. If you're a beginner to Python, then this tutorial will definitely help you on your journey as you take your first steps into the world of programming.

basics python

For additional information on related topics, take a look at the following resources:


By Leodanis Pozo Ramos • Updated July 25, 2025