Pygame Zero (the pgzero package) is a layer on top of pygame, made for teaching. It writes the game loop for you. You define a draw() function and an update() function, and Pygame Zero calls them sixty times a second. Images become Actor objects that are loaded from an images folder by name.
Pygame is the library underneath: you write the loop, read the events, load the images and call flip() yourself.
The same game in both
A ship that moves with the arrow keys. In Pygame Zero:
import pgzrun
WIDTH = 480
HEIGHT = 360
ship = Actor("ship") # loads images/ship.png
ship.pos = (240, 180)
def draw():
screen.fill((10, 12, 30))
ship.draw()
def update():
if keyboard.left:
ship.x -= 5
if keyboard.right:
ship.x += 5
pgzrun.go()
WIDTH, HEIGHT, Actor, screen and keyboard come from Pygame Zero, which is why there are no imports for them. In pygame the same program writes those parts out:
About ten more lines, and each one is something you can see and change: the window, the clock, the event loop and the frame flip. Press Play, click the game and fly left and right.
Side by side
| Pygame Zero | Pygame | |
|---|---|---|
| Install | pip install pgzero (installs pygame too) | pip install pygame-ce |
| Run | pgzrun main.py, or pgzrun.go() at the end | python main.py |
| Game loop | Hidden: you write draw() and update() | You write the while loop |
| Images | Actor("ship") from an images folder | pygame.image.load() and blit() |
| Input | keyboard.left, on_key_down(), on_mouse_down() | pygame.key.get_pressed() and events |
| Sound | sounds.coin.play() from a sounds folder | pygame.mixer.Sound("coin.ogg").play() |
| Timers | clock.schedule(fn, 2.0) | pygame.time.set_timer() or get_ticks() |
| Made for | Classrooms and first games | Any 2D game, any size |
Which should you use?
Pygame Zero is good for a first afternoon, a young learner or a class, because a moving character takes very few lines and the Mu editor runs it with one button. It is also good to know that its conventions (folders named images and sounds, magic global names) are its own: code from a Pygame Zero tutorial does not run in plain pygame.
Plain pygame is the better place to learn if you want to understand games. The game loop, events and drawing are all in your code, every pygame tutorial and answer applies, and nothing is hidden when a bigger game needs control over it. The move is not big: an Actor becomes an image plus a Rect, draw() becomes the drawing part of your loop, and update() its update part.
Frequently Asked Questions
What is Pygame Zero?
A Python library built on pygame for teaching, especially in schools. It runs the game loop for you: you write draw() and update() functions, use Actor objects for images, and start the game with pgzrun.
Is Pygame Zero easier than pygame?
For a first game, yes: there is no window setup, event loop or clock to write. The cost is that the loop, events and image loading are hidden, so you learn less about how games work and have less control as games grow.
Can I use pygame functions in a Pygame Zero game?
Yes. Pygame Zero runs on pygame, so import pygame works inside a Pygame Zero program, for example to use pygame.Rect or pygame.transform.