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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

turtle_widget-1.0.3.tar.gz (523.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

turtle_widget-1.0.3-py3-none-any.whl (43.8 kB view details)

Uploaded Python 3

File details

Details for the file turtle_widget-1.0.3.tar.gz.

File metadata

  • Download URL: turtle_widget-1.0.3.tar.gz
  • Upload date:
  • Size: 523.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for turtle_widget-1.0.3.tar.gz
Algorithm Hash digest
SHA256 82992c5426631e8419154b29db86fde6cb207d6f8265c2d8b3af53d381597c42
MD5 7836a757aeac7b70aa6abd65365135a7
BLAKE2b-256 393daa26b5b904495c630cf8ee9a270e125fd38bafc06b520b5640b1901a02b3

See more details on using hashes here.

File details

Details for the file turtle_widget-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: turtle_widget-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 43.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for turtle_widget-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 734f070f9ce0c7d46da960a1e06001b3f095ed5ce2fd22776179f649c76893f0
MD5 de1de1b8e7c926db2cb1fad65bb08554
BLAKE2b-256 fca3ec446c6bd1edca9628536e7a2431d75d73a83088ba9a8b11db1a5b7341f5

See more details on using hashes here.

Release history Release notifications | RSS feed

1.0.9

2 files

1.0.7

2 files

1.0.5

2 files

This release

1.0.3 This release

2 files

1.0.1

2 files

0.1.28

2 files

0.1.26

2 files

0.1.24

2 files

0.1.22

2 files

0.1.20

2 files

0.1.18

2 files

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