1
Home
Tirsvad edited this page 2026-11-15 13:28:32 +01:00

English · Dansk · Bahasa Melayu

Etch-A-Sketch

An Etch-A-Sketch drawing app: steer a turtle with the keyboard and draw.

What is it?

Day 19 of the Udemy course 100 Days of Code: The Complete Python Pro Bootcamp, on event listeners. A window opens with a turtle in the centre. You press W to move forwards, S to move backwards, A to turn left, D to turn right and C to clear the drawing and return the turtle to the centre. The control functions keep the names from the assignment (move_forwards, move_backwards, turn_left, turn_right and clear) and take no arguments, because Screen.onkey accepts only functions without arguments.

What the exercise teaches

  • Listening for key presses with Screen.listen and Screen.onkey
  • Writing functions without arguments, as event listeners require
  • Moving and turning the turtle to draw lines
  • Keeping constants such as the step length, the turn angle and the key names in one module
  • Testing the controls with test doubles for the turtle and the screen, so no window opens

What it does

  • Five keyboard controls: W, S, A, D and C, in upper or lower case
  • The assignment's function names move_forwards, move_backwards, turn_left, turn_right and clear
  • Click the window to close it
  • No runtime dependencies beyond the Python standard library

Next