Pygame API reference

Practical notes on the modules you use most, with parameters, return values, tested examples, common errors and links to the official documentation.

Modules

How this reference is organised#

Each page explains one module or class: what it is for, its most important functions with parameters and return values, a complete program that uses it, and the errors people run into. Where pygame and pygame-ce differ in ways that matter, the page says so. Signatures were checked against pygame 2.6.1 and pygame-ce 2.5.8.

This is a learning-focused companion, not a replacement for the official documentation, which lists every function and option:

Other modules#

pygame.mask (pixel-perfect collision masks), pygame.joystick (gamepads), pygame.image (loading and saving), pygame.key and pygame.mouse are explained where you need them in the tutorials and articles. For example, collision detection explains masks and joystick input covers gamepads.

Where things live#

You want to…Module
Open a window or go fullscreenpygame.display
Draw shapespygame.draw
React to keys, mouse, window eventspygame.event
Load, combine or make images transparentpygame.Surface
Position objects and test collisionspygame.Rect
Manage many game objectspygame.sprite
Play sounds and musicpygame.mixer
Show textpygame.font
Control frame rate and timerspygame.time
Scale, rotate or flip imagespygame.transform
Work with directions and velocitiespygame.math
↑ ↓ to moveEnter to openEsc to close