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>"
return 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file basthon_turtle-0.0.5.tar.gz.
File metadata
- Download URL: basthon_turtle-0.0.5.tar.gz
- Upload date:
- Size: 19.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2686c18ad63da0b7deee187e40ed8760991ba07c9b4a331864a6311e5201f55c
|
|
| MD5 |
5dcb7cc324963d5b129fa50b14a53987
|
|
| BLAKE2b-256 |
d7a65cd2c6c6d7bc458ba6426e2609374cadb309c3e71afd52bd4a5f02fb67c6
|
File details
Details for the file basthon_turtle-0.0.5-py3-none-any.whl.
File metadata
- Download URL: basthon_turtle-0.0.5-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a8504b0d26ea13b3eacd72017af85158aabf6877d2c4485678d925f8a81d302b
|
|
| MD5 |
4f5c8c519b13e0d85f6771894bfa7986
|
|
| BLAKE2b-256 |
be3a93cfc1643248ee703923f2ee1bfd927f724f11b784f72a604b605a04d3a2
|