A free, open-source Python library for creating 2D video games, multimedia programs, and interactive simulations
documentation: https://www.pygame.org/docs
Start by trying a basic example that goes full screen and prints some text in the center. It looks for the user to click the ESC key to stop running the code. The code is called pygame_basic.py
Try changing the colors and the text.
Now try making a shape using pygame_simple_shape.py Note that this example is not full screen.
Try changing the colors and the shape.
Try making the image full screen and adding the esc key as a way to exit the application.
This example uses keyboard input to move an object around the screen pygame_movement.py. Note that this example is not full-screen and can only be quit by using the code stop button in Thonny or closing the window.
Try changing the colors, the shape, and the way it moves.
Try making the image full screen and adding the esc key as a way to exit the application.
This example uses any touchscreen input to draw randomly located hearts on the screen.
Try changing the shape, size, and the colors.
Try making the image full screen and adding the esc key as a way to exit the application.
Can you figure out a way to hide the cursor?
Some of the most important things to know about Pygame:
How to incorporate a key input function to exit (this example uses ESC):
How to create a full-screen drawing:
How to hide the cursor
Other important resources:
Here are your keyboard input codes: https://www.pygame.org/docs/ref/key.html
Shapes you can draw: https://www.pygame.org/docs/ref/draw.html
Challenges
Can you create an application that draws something when the mouse is clicked?
Can you have an external button do something in a Pygame window?
Can you represent a sensor value in Pygame?
If you don't have Pygame installed:
Installation: sudo pip3 install pygame
if that doesn't work, try:
sudo pip3 install pygame --break-system-packages