Module 4 - Section 2 - Graphics
- identify the commands inside the Pygame basic template
- experiment with various graphics commands
- draw shapes using Python commands
- draw text using Python commands
4.2.4 - User interaction and event processing
With just the code written so far, the program would create a window and immediately hang. The user can't interact with the window, even to close it. All of this interaction needs to be programmed. Code needs to be added so that the program waits in a loop until the user clicks “exit.”
This is the most complex part of the program, and a complete understanding of it isn't needed yet. But it is necessary to have an idea of what it does, so spend some time studying it and asking questions.
There are many other events that we can process :
The events (like pressing keys) all go together in a list. The program uses a for loop to loop through each event. Using a chain of if statements, the script figures out what type of event occurred. The code to handle that event goes in the if statement.