We use essential cookies to make our site work. We’d also like to use optional analytics cookies to help us improve it. We do not use advertising cookies. You can accept all cookies or continue with essential cookies only.
Learn more.
Cookie Settings
Manage your cookie preferences below:
These are required for the website to function correctly.
Helps us improve the site by understanding usage patterns.
We don’t use ads and we don’t send ad-tracking information to third-party vendors.
In the PyGame programs we have seen so far, the user could not affect their execution, aside from ending the program. We can compare this kind of programs to watching movies - the user is essentially a viewer.
In the next section, we will deal with programs in which the user has an active role and can influence the running of the program using a mouse and a keyboard. There are two basic ways for our program to “know” when the user has made an action.
One way is to read the status of the mouse and keyboard. From the code we can ask what is the current position of the mouse, whether any key is being pressed and the like.
Another way is to use system events. Any user action (pressing a mouse button or a keyboard key, releasing a key, moving the mouse, etc.) is an event, and in the programs we can obtain information about such events and respond to them.
In this chapter, we will familiarize with both of these ways that enable our programs to respond to user actions.
Please fill in all fields that are marked as required.An error occurred while submitting your response.Your response has been submitted. Thank you!Your responses have been submitted. Thank you!