week 13 event driven programming Flashcards
event
when something happens (ex: user clocks button)
turtle events
t.onclick()
t.ondrag()
t.onrelease()
screen events
s.onclick()
s.onkey()
s.ontimer()
additional functions needed for screen events
s.listen()
s.mainloop()
onkey() call for screen event
s.onkey(up, “up”)
up is function that specifies instructions when the up key is clicked
onclick() call for turtle event
t.onclick(whenPressed)
funciton whenPressed takes x, y coordinates as arguments
why are global variables useful for turtle events?
the only parameters the function can take are x,y coordinates, anything else should be a global var
are turtles global variables?
yes.
steps for screen events
1) set up screen
2) set up events and specify functions
3) call listen() and mainloop() functions