1. Pyroom
  2. Tutorials
  3. Python Turtle
  4. Control a turtle with the keyboard

Control a turtle with the keyboard

Events turn a drawing into a game. onkey connects a key to a function, and listen starts waiting for presses.

Advanced Video coming soon. The steps below show everything the video will cover.

Steps

  1. Write one small function for each move.
  2. onkey connects each arrow key to a function. listen starts waiting for presses.
  3. Run it, then click the drawing so it receives the keys.
  4. Now drive the turtle with the arrow keys.
Read the transcript

Write one small function for each move.

onkey connects each arrow key to a function. listen starts waiting for presses.

Run it, then click the drawing so it receives the keys.

Now drive the turtle with the arrow keys.

Try it in the Playground

Nothing to install and no account needed.

Open Playground →