13.3 Event-Driven Programming with the Turtle
The turtle module provides three methods to register callbacks for key, mouse, and timer events:
onkey
onclick
ontimer
In addition, the listen method is used to give the turtle canvas focus so that the event handler can respond to key presses. Each method has conventions for the parameters it accepts. Table 13.3 explains each of these methods to register callbacks for events, as well as the listen method.
Table 13.3 Turtle Methods to Register Callbacks
Method | Description |
---|---|
onkey(function, key) | Binds a function to a key press so that function is called when a specified key is pressed. The function must take no parameters. key is a string representing a key on the keyboard. The keyboard must ... |
Get Python Programming in Context, 4th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.