Tirsvad dda6b7b639
TirSystem/git-workflows: Release / release (push) Skipped
TirSystem/git-workflows: Sync GitHub mirror metadata / sync-metadata (push) Successful in 23s
TirSystem/git-workflows: Publish wiki / publish-wiki (push) Successful in 41s
TirSystem/git-workflows: Publish accepted milestones / publish (push) Successful in 34s
TirSystem/git-workflows: Validate / validate (push) Successful in 30s
TirSystem/git-workflows: OpenGrep / opengrep (push) Successful in 1m47s
CI / Checks (push) Successful in 1m9s
Merge pull request 'Bring the project to the framework baseline (MIL-004)' (#33) from mil-004-baseline into main
2026-11-15 13:27:51 +01:00
2026-11-15 20:22:24 +08:00
2026-10-08 11:41:49 +08:00
2026-10-07 16:38:16 +02:00

Etch-A-Sketch

An Etch-A-Sketch drawing app written with Python's turtle graphics: steer the turtle with the keyboard and draw. It is the Day 19 assignment of Udemy's 100 Days of Code: The Complete Python Pro Bootcamp, and it shows how event listeners detect key presses.

📚 Table of Contents

🧭 Overview

Key Action
W Move forwards
S Move backwards
A Turn left
D Turn right
C Clear the drawing and return the turtle to the centre

Click the window to close it. The control functions keep the assignment's names (move_forwards, move_backwards, turn_left, turn_right and clear) and take no arguments, because Screen.onkey accepts only functions without arguments.

The Etch-A-Sketch window with a heart drawn using the keys W, A and D

The heart above is drawn with the keys alone, starting at the centre, in 118 key presses:

  1. A 6 times, to turn the turtle up and to the right.
  2. W, D 20 times in turn, for the first lobe.
  3. W 12 times, down to the point.
  4. D 8 times, to turn at the point.
  5. W 12 times, up to the second lobe.
  6. D, W 20 times in turn, for the second lobe.

Project layout

src/etch_a_sketch/
    __init__.py     package description
    __main__.py     entry point for python -m etch_a_sketch
    app.py          creates the turtle and screen and binds the keys
    constants.py    step length, turn angle and key names
    controls.py     move_forwards, move_backwards, turn_left, turn_right, clear
tests/              pytest tests and the test doubles they use
docs/               planning documents: business case, plan, milestones, reviews, wiki
framework/          quality framework used for the documents (git submodule)
.editorconfig       editor settings of the framework baseline
.env.example        placeholders for the tokens of the framework scripts
.github/workflows/  continuous integration workflow
Doxyfile            Doxygen configuration
pyproject.toml      project configuration (Python 3.13 or newer, no runtime dependencies)
AGENTS.md           rules for AI agents working in this repository

The framework/ submodule is not needed to run the application or the tests, so a plain git clone is enough.

📋 Requirements

  • Python 3.13 or newer, with Tk support (tkinter), which turtle uses to draw. Check with python -c "import tkinter": no output means it works.
  • Git, to clone the repository.
  • Doxygen, only if you want to build the source documentation. It is a system tool, not a Python package.
  • There are no runtime dependencies. pytest, ruff and mypy are development tools, installed with the dev extra below.

🛠️ Setup

The commands create a local virtual environment in the folder .venv, with its own Python and packages, so nothing is installed system-wide. Create it once; activate it in every new terminal; leave it with deactivate.

The commands were run and checked on Windows PowerShell with Python 3.13.14. The Debian and macOS commands are the standard equivalents; they have not been run by the author, and the continuous integration workflow runs on Linux.

Windows powershell

git clone https://git.tirsystem.com/Tirsvad-Udemy-100-days-of-code/019-etch-a-sketch-up.git
cd 019-etch-a-sketch-up
python --version
python -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install --upgrade pip
python -m pip install -e ".[dev]"

python --version must show 3.13 or newer. If PowerShell refuses to run Activate.ps1, allow scripts for this window only and run the activation again:

Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass

Linux debian

Debian 13 ("trixie") provides Python 3.13. On an older release, install Python 3.13 another way (for example with pyenv) and make sure it has Tk before you create the environment.

sudo apt update
sudo apt install git python3 python3-venv python3-tk
git clone https://git.tirsystem.com/Tirsvad-Udemy-100-days-of-code/019-etch-a-sketch-up.git
cd 019-etch-a-sketch-up
python3 --version
python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install -e ".[dev]"

MacOS

Install Python 3.13 from python.org (it includes Tk), or with Homebrew: brew install python@3.13 python-tk@3.13.

git clone https://git.tirsystem.com/Tirsvad-Udemy-100-days-of-code/019-etch-a-sketch-up.git
cd 019-etch-a-sketch-up
python3 --version
python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install -e ".[dev]"

▶️ Run

With the environment active:

python -m etch_a_sketch

A window opens with the turtle in the centre. Press W, S, A, D and C (upper or lower case, so Caps Lock does not matter) and click the window to close it. The window needs a desktop session; it cannot open over a plain SSH connection.

Build the source documentation

The source has Doxygen comments (@brief, @param, @return). Install Doxygen, then build the HTML pages:

winget install DimitriVanHeesch.Doxygen   # Windows
sudo apt install doxygen                  # Linux debian
brew install doxygen                      # MacOS
doxygen Doxyfile

Open docs/doxygen/html/index.html. The build stops on any warning, so every public class, function and constant needs a Doxygen comment. The folder docs/doxygen/ is generated and not tracked by git.

🧪 Tests

With the environment active:

python -m pytest

The tests use test doubles for the turtle and the screen, so no window opens and no display is needed. Before a pull request, also run the checks that the continuous integration runs:

ruff check .
ruff format --check .
mypy

Continuous integration

.github/workflows/ci.yml runs on every push to main and every pull request. It installs the system packages Tk (libtk8.6, which turtle needs even though the tests open no window) and Doxygen with apt, installs Python 3.13 and the project with .[dev], then runs ruff check ., ruff format --check ., mypy, pytest and doxygen Doxyfile, and fails on the first error. Gitea Actions and GitHub Actions both read the file; the runner needs the label ubuntu-latest. Run the same commands locally before you open a pull request.

📄 License

GNU Affero General Public License v3.0. See LICENSE.

📎 Appendix: Project documents

The documents a newcomer needs, in reading order.

Document What it tells you
Business Case Why the project exists, its scope and success criteria
Stakeholder Analysis Who is involved; the stakeholder IDs used for owners and reviewers
Project Plan The milestones and their schedule
Milestones One document per milestone: Go/No-Go criteria and tasks
Artifact registry Where each artifact type lives, the next version, the PO language and domain
Traceability matrix How the artifacts link and when each was last reviewed

S
Description
Etch-A-Sketch drawing app in Python: steer a turtle with the keyboard (W/S move, A/D turn, C clear). Day 19 of Udemy's 100 Days of Code: The Complete Python Pro Bootcamp. No runtime dependencies.
Readme AGPL-3.0
313 KiB
0 Stars 1 Watchers 0 Forks
Languages
Python 100%