Skip to main content

turtle-widget

An animated, turtle-compatible drawing widget for Jupyter notebooks, built on anywidget.

You write ordinary turtle code in Python; the widget records each command and replays it as a smooth canvas animation right below the cell. Because it is built on anywidget, it behaves identically in VS Code, JupyterLab, Notebook 7, and Colab, and works offline. Optionally it shows the cell source beside the canvas and highlights the active line in sync with the animation (show_code=True).

Installation

# pixi
pixi workspace channel add munch-group
pixi add turtle-widget

# conda
conda install -c munch-group turtle-widget

# pip
pip install turtle-widget

Quick start

from turtle_widget import Turtle

t = Turtle()
t.speed(6)
for _ in range(4):     # a square
    t.forward(120)
    t.left(90)

The widget appears automatically at the end of the cell — no need to put t on the last line. You can also display it explicitly with t.show(), or evaluate t. Pass autoshow=False to build a turtle without displaying it (useful for headless geometry checks).

Most of the common turtle API is supported: forward/backward, left/right, goto/setheading/home, circle, pen control (penup/pendown/pensize), colours and fills (pencolor/fillcolor/begin_fill/end_fill), and markers/text (dot/stamp/write). Note that the pen-width method is pensize() (the name width is the canvas-size trait).

Multiple turtles

Two or more turtles can share one canvas — different colours, a race, one sensing the other's trail:

from turtle_widget import Turtle

t1 = Turtle()
t2 = t1.new_turtle(color="red")
t1.forward(100)
t2.forward(60)

t1.new_turtle(...) creates a turtle that draws on t1's canvas instead of building one of its own. Each turtle keeps its own position, heading, and pen; commands still animate in the order you write them, one at a time — there is no simultaneous animation.

Documentation

Full docs and a guided showcase live at munch-group.org/turtle-widget.

Development

This repo is managed with pixi:

pixi run install-dev   # editable install into the pixi environment
pixi run test          # run the pytest suite
pixi run docs          # execute the documentation notebooks
pixi run api           # build the quartodoc API reference

License

MIT

Metadata

Release files for turtle-widget 1.0.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for turtle-widget 1.0.10
File Size Uploaded Provenance Actions
turtle_widget-1.0.10.tar.gz 898.0 kB Without provenance Details for turtle_widget-1.0.10.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for turtle-widget 1.0.10
File Interpreter ABI Platform Actions
turtle_widget-1.0.10-py3-none-any.whl Python 3 none any Details for turtle_widget-1.0.10-py3-none-any.whl

Total release size: 949.6 kB

Release files / turtle_widget-1.0.10.tar.gz

Download URL turtle_widget-1.0.10.tar.gz
Size 898.0 kB
Tags Source
SHA-256 checksum
How to use checksums
ffa742fe3c90440ad79d6299c22f44c37248e3207443c451c0d5245d7b9502c0
BLAKE2b-256 checksum
How to use checksums
056044a4b79d05e658c941636b160100b2ada93821443a448b872a06121bbed4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / turtle_widget-1.0.10-py3-none-any.whl

Download URL turtle_widget-1.0.10-py3-none-any.whl
Size 51.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5942559bd5239a70af9fb769961b8fd5d3e778c0db7c6e259c0821468295138b
BLAKE2b-256 checksum
How to use checksums
fd27d5d585a39faef7b8c3530ada6c0e50d623307675043c164989d815ea608e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Security for turtle-widget 1.0.10

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page