Mainloop call (line 31) to end its execution. While executing h4, the window’s bye method (line 24) closes the turtle window, which causes the window’s Pressing the q key on the keyboard calls function h4 (because we bound the q key to h4 on line 26).The handlers can beĪrbitrarily complex functions that call other functions, etc. We named our handler functions h1, h2 and so on, but we can choose better names.We need the call to the window’s listen method at line 31, otherwise it won’t notice our keypresses.onkey ( h4, "q" ) # Now we need to tell the window to start listening for events, # If any of the keys that we're monitoring is pressed, its # handler will be called. bye () # Close down the turtle window # These lines "wire up" keypresses to the handlers we've defined. Turtle () # Create our favorite turtle # The next four functions are our "event handlers". bgcolor ( "lightgreen" ) # Set the background color tess = turtle. title ( "Handling keypresses!" ) # Change the window title wn. Screen () # Get a reference to the window wn. setup ( 400, 500 ) # Determine the window size wn = turtle.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |