On this page
  1. turtle
  2. Import
  3. Overview
  4. Quick Start
  5. Implementation Walkthrough
  6. 1. Speeding Up Complex Drawings (tracer(0) + update())
  7. Gotchas & Boundaries
  8. Common Functions
  9. Classes & Objects

turtle

Prev: tty | Up: stdlib_module | Next: turtledemo
Rel: wave, colorsys, gettext, locale, turtledemo
Ref: docs.python.org — turtle
Tags: #public #python3 #stdlib


Import

import turtle

Overview

Logo-style vector graphics and educational drawing library built on top of tkinter (Turtle, Screen, forward(), right(), penup(), pendown()). Use turtle for teaching programming concepts, visualizing recursive fractals/L-systems, or sketching quick 2D geometric animations with zero third-party installs.

Quick Start

# Run in a desktop environment with Tkinter available:
import turtle

def draw_square(size: int = 100) -> None:
    t = turtle.Turtle()
    for _ in range(4):
        t.forward(size)
        t.right(90)
    turtle.done()

Implementation Walkthrough

1. Speeding Up Complex Drawings (tracer(0) + update())

By default, turtle animates every single step. Disable live animation with screen.tracer(0) and call screen.update() once at the end to render fractals or hundreds of shapes instantaneously:

import turtle

def draw_star(points: int = 5, length: int = 120) -> None:
    screen = turtle.Screen()
    screen.tracer(0)
    t = turtle.Turtle()
    for _ in range(points):
        t.forward(length)
        t.right(180 - 180 / points)
    screen.update()
    turtle.done()

Gotchas & Boundaries

Common Functions

Classes & Objects

Linked from

Related notes