Getting started
Install Pygame and open your first window. The ten lines every game starts with.
Build your first game with Python, explore powerful development tools, learn with practical tutorials, and run Pygame code directly in your browser.
import pygame pygame.init()screen = pygame.display.set_mode((320, 240))clock = pygame.time.Clock()ball = pygame.Vector2(160, 60)vel = pygame.Vector2(150, 120)paddle = pygame.Rect(130, 220, 60, 8) while True: for event in pygame.event.get(): if event.type == pygame.QUIT: raise SystemExit if event.type == pygame.MOUSEMOTION: paddle.centerx = event.pos[0] dt = clock.tick(60) / 1000 ball += vel * dt if not 6 < ball.x < 314: vel.x *= -1 if ball.y < 6: vel.y *= -1 if paddle.collidepoint(ball): vel.y = -abs(vel.y) screen.fill((22, 26, 19)) pygame.draw.circle(screen, "yellow", ball, 6) pygame.draw.rect(screen, (105, 240, 42), paddle) pygame.display.flip()
Try it: move the paddle. This preview is drawn with JavaScript; run the Python version in Pygame Online.
Pygame is a free, open-source Python library for making 2D games and multimedia programs. It wraps SDL, a widely used C library for graphics, sound and input, so you write plain Python while the heavy lifting runs in compiled code.
The project started in 2000 and is one of the most common ways people learn game programming in Python. Two packages are maintained today: the original pygame and the community edition pygame-ce, a compatible fork with more frequent releases. Code from this site runs on both. Compare the two packages.
Each area maps to a module you can look up in the API reference.
displayOpen windows, go fullscreen, scale and update the screen.
drawLines, rectangles, circles, polygons and arcs, with or without fills.
SurfaceLoad images, blit them, use transparency and per-pixel alpha.
eventKeyboard, mouse, joystick and window events in one queue.
spriteOrganise game objects into groups and test collisions between them.
mixerPlay sound effects on channels and stream background music.
fontRender text for scores, menus and dialogue.
mathVector2 and Vector3 for movement, angles and physics.
Every Pygame program follows the same shape: start Pygame, open a window, then loop, handling events, updating the game and drawing a frame. Once you see this pattern, every game on this site will look familiar.
The getting started tutorial walks through each line, and the game loop lesson explains frame rates and delta time.
import pygame
pygame.init()
screen = pygame.display.set_mode((640, 480))
clock = pygame.time.Clock()
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
screen.fill("cornflowerblue")
pygame.display.flip()
clock.tick(60)
pygame.quit()Pygame Online runs real Python in your browser using WebAssembly and pygame-ce. Edit an example, press Run and see the result next to your code.
print() output and tracebacks that point at your line numbers.
Step-by-step lessons with code you can run and change.
Install Pygame and open your first window. The ten lines every game starts with.
A complete catch game with score, lives, difficulty and restart.
Events, update, draw. Frame rate, delta time and smooth movement.
Load images, convert_alpha(), and organise objects with Sprite and Group.
Rects, circles, masks, sprite groups and resolving overlaps.
Tiles, gravity, responsive jumps and a scrolling camera.
Follow the stages in order; each one ends with something you can play.
Get a window on screen and understand the loop.
Move things around and make them react to each other.
Add physics, sound, menus and levels.
Ten original games, each in a single Python file with no asset downloads.
Grid movement, a growing tail and buffered turns.
Paddles, rebound angles and a beatable computer opponent.
Brick grids, side-aware bounces, lives and levels.
Sprites, bullets, enemy waves and particle explosions.
Tiles, responsive jumping and a scrolling camera.
Rotation, wall kicks, line clears and a ghost piece.
Everything runs in your browser; your images never leave your computer.
Draw sprites and tiles, export transparent PNGs.
Pack animation frames into one PNG with frame data.
Paint levels and export JSON or CSV with loader code.
Drag shapes to see collision tests and code live.
HEX, RGB, HSL and Pygame tuples with a saved palette.
A starter game loop with your window, FPS and options.
Combine components into a runnable starter game.
Explore screen coordinates, points and Rect attributes.
Practical notes, parameters and tested examples for the parts of Pygame you use most.
pygame.displayWindows, resolutions, fullscreen and showing frames.pygame.drawRectangles, circles, lines, polygons and arcs.pygame.eventThe event queue, event types and custom events.pygame.SurfaceImages in memory, blitting and transparency.pygame.RectPositions, sizes, alignment and collision tests.pygame.spriteSprite and Group classes and collision helpers.pygame.mixerSound effects, channels and streamed music.pygame.fontFonts, rendering and measuring text.pygame.timeFrame rate, delta time, timers and delays.pygame.transformScaling, rotation, flipping and filters.pygame.mathVector2, Vector3 and helper functions.Both packages use import pygame, and the games on this site run on either. The main practical difference is release frequency and support for the newest Python versions. Install only one of them in a given environment.
| pygame | pygame-ce | |
|---|---|---|
| Install | pip install pygame | pip install pygame-ce |
| Latest release | 2.6.1 (September 29, 2024) | 2.5.8 (August 9, 2026) |
| Prebuilt wheels for | Python 3.6–3.13 | Python 3.10–3.14 |
| Import name | pygame | pygame |
Prebuilt packages exist for the three major desktop systems, so pip installs Pygame without a compiler on supported Python versions.
Yes. Pygame and pygame-ce are open source under the GNU LGPL version 2.1. You can use them for free in personal and commercial projects; the license's terms apply if you distribute modified versions of the library itself.
It is one of the gentlest ways to learn game programming because a game is just Python code: no editor, scene files or build pipeline. You do need basic Python first: variables, loops, functions and lists. The tutorials assume only that.
Use a current Python 3 release that the package has prebuilt wheels for. pygame 2.6.1 ships wheels for Python 3.6–3.13; pygame-ce 2.5.8 ships wheels for Python 3.10–3.14. On newer Python versions without wheels, pip tries to compile from source, which usually fails. See Python compatibility.
Pygame is built for 2D. You can combine it with OpenGL through PyOpenGL for 3D, but if 3D is your main goal, a 3D engine is usually a better fit.
Yes, many people do. The LGPL allows commercial use. When you bundle Pygame with your game (for example with PyInstaller), include the license text and make sure players can replace the library, as the LGPL requires. This is general information, not legal advice.
pygame-ce has a WebAssembly build used by tools such as Pyodide and pygbag, which is how Pygame Online works. Native Android and iOS apps are possible with third-party packaging tools but are not officially supported.
Install Pygame, open the first tutorial and have a window on screen in ten minutes, or start in the browser right now.