Skip to main content

An animated, turtle-compatible drawing widget for Jupyter notebooks

Project description

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).

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

Project details


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-0.1.18.tar.gz (458.9 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-0.1.18-py3-none-any.whl (36.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: turtle_widget-0.1.18.tar.gz
  • Upload date:
  • Size: 458.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for turtle_widget-0.1.18.tar.gz
Algorithm Hash digest
SHA256 350f36c18c6f6692d24e6e7415f5b2ef54832e9b6cad721fba01513391298086
MD5 120c52561e9fb96b2d57d90f4f69dabf
BLAKE2b-256 eacfd7612f120eb0a1f888eae357cd1638a8e540290b884f9b96250c1c876a9a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: turtle_widget-0.1.18-py3-none-any.whl
  • Upload date:
  • Size: 36.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for turtle_widget-0.1.18-py3-none-any.whl
Algorithm Hash digest
SHA256 4242be2b0dec8cd654a9d09ff3c0f7a5cb1f79b9c14f27104b3b6fbd8c6e4a8d
MD5 ec9b3d44bd42c203e6757fc8285dab9d
BLAKE2b-256 f22a47e26114d5d9dc757b2b9f5b2cf06b6b2077bae0fb209354b01e26b88e24

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page