Skip to main content

A revised version of CPython’s turtle module, browser-friendly.

Note: This version is not intended to be used in interactive mode, nor use help() to look up methods/functions definitions. The docstrings have thus been shortened considerably as compared with the CPython’s version.

All public methods/functions of the CPython version should exist, if only to print out a warning that they are not implemented. The intent is to make it easier to “port” any existing turtle program from CPython to the browser.

Initially the code was part of Brython, then ported to Basthon, then published as a standalone package.

Installation

pip install basthon-turtle

or

import micropip
await micropip.install('basthon-turtle')

Usage

Note: if running multiple times you need to restart the state of screen with turtle.restart() function.

Jupyter

from IPython.display import HTML
from turtle import forward, done, svg

forward(100)
done()

HTML(svg())

Marimo

import marimo as mo

from turtle import forward, done, svg

forward(100)
done()
forward(100)
mo.Html(svg())

webbrowser

import webbrowser
from urllib.parse import quote

from turtle import forward, done, svg


def show_svg(svg_content: str) -> bool:
    html = f"<!doctype html><html><body>{svg_content}</body></html>"
    retrun webbrowser.open(f"data:text/html,{quote(html)}")


forward(100)
done()

show_svg(svg())

Credits

  • bearney74

  • André Roberge

  • Romain Casati

Implementation

Download files

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

Source Distribution

basthon_turtle-0.0.4.tar.gz (19.5 kB view details)

Uploaded Source

Built Distribution

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

basthon_turtle-0.0.4-py3-none-any.whl (18.7 kB view details)

Uploaded Python 3

File details

Details for the file basthon_turtle-0.0.4.tar.gz.

File metadata

  • Download URL: basthon_turtle-0.0.4.tar.gz
  • Upload date:
  • Size: 19.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.0

File hashes

Hashes for basthon_turtle-0.0.4.tar.gz
Algorithm Hash digest
SHA256 05b6bc0224e77f8af8f8dba761e16c6643e8ccfdce58ecb2d00defa1751e29cb
MD5 fc387b05b565dff61f5f7afdaf864da4
BLAKE2b-256 7b91737f5231bf22922776e46350b346074acc1873d7faf64ab7b1602279a57d

See more details on using hashes here.

File details

Details for the file basthon_turtle-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: basthon_turtle-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 18.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.0

File hashes

Hashes for basthon_turtle-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 58d29dbee73375eafe475da03dd9c374365d978427dc6ca74108cc63b766a63c
MD5 f76d2301eb0564ff1ceb868a718ea13f
BLAKE2b-256 8681aba8867b64dabdc6d1d2afd7670155b98cccd82e9e3f47896b349b610cd5

See more details on using hashes here.

Release history Release notifications | RSS feed

0.4.0

2 files

0.3.1

2 files

0.3.0

2 files

0.2.0

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

0.0.5

2 files

This release

0.0.4 This release

2 files

0.0.3

2 files

0.0.2

2 files

0.0.1

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