Pygame Create games with Python

Build your first game with Python, explore powerful development tools, learn with practical tutorials, and run Pygame code directly in your browser.

  • Free and open source (LGPL)
  • Windows, macOS and Linux
  • pygame 2.6.1 and pygame-ce 2.5.8
paddle.py
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.

Install in one command

Needs Python 3 and pip. Works in a virtual environment too.

pip install pygame

What is Pygame?

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.

  • Plain PythonNo engine editor or scene format to learn. A game is a Python file you can read top to bottom.
  • Runs everywhere Python doesPrebuilt wheels for Windows, macOS and Linux, and a WebAssembly build for the browser.
  • Great for learningSmall enough to understand, complete enough to finish real games.

What you can do with it

Each area maps to a module you can look up in the API reference.

display

Open windows, go fullscreen, scale and update the screen.

draw

Lines, rectangles, circles, polygons and arcs, with or without fills.

Surface

Load images, blit them, use transparency and per-pixel alpha.

event

Keyboard, mouse, joystick and window events in one queue.

sprite

Organise game objects into groups and test collisions between them.

mixer

Play sound effects on channels and stream background music.

font

Render text for scores, menus and dialogue.

math

Vector2 and Vector3 for movement, angles and physics.

Your first window in a few lines

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.

Start the first tutorial

first_window.py
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()

Run Pygame without installing anything

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.

  • 17 examples and gamesFrom “Hello Pygame” to a complete space shooter.
  • Console and readable errorsSee print() output and tracebacks that point at your line numbers.
  • Private by designCode runs in a sandbox in your browser and is never uploaded.

Open Pygame Online

The Star Patrol space shooter, one of the games you can play in Pygame Online

Popular tutorials

Step-by-step lessons with code you can run and change.

All 15 tutorials

Getting started

Install Pygame and open your first window. The ten lines every game starts with.

Beginner4 min

The game loop

Events, update, draw. Frame rate, delta time and smooth movement.

Beginner4 min

Images and sprites

Load images, convert_alpha(), and organise objects with Sprite and Group.

Beginner3 min

Collision detection

Rects, circles, masks, sprite groups and resolving overlaps.

Intermediate3 min

Platformer game

Tiles, gravity, responsive jumps and a scrolling camera.

Advanced2 min

A learning path for beginners

Follow the stages in order; each one ends with something you can play.

1

Foundations

Get a window on screen and understand the loop.

  1. Getting started
  2. The game loop
  3. Drawing shapes
  4. Keyboard input
2

Game objects

Move things around and make them react to each other.

  1. Images and sprites
  2. Collision detection
  3. Build your first game
  4. Study the Snake source
3

Complete games

Add physics, sound, menus and levels.

  1. Game physics
  2. Sound and music
  3. Menus and game states
  4. Build a platformer

Game projects with full source code

Ten original games, each in a single Python file with no asset downloads.

All game projects
Snake game screenshot: a blue snake on a checkered board heading towards a yellow pellet

Snake

Grid movement, a growing tail and buffered turns.

Beginner
Pong screenshot: blue player paddle, yellow computer paddle, white ball and a 4 to 3 score

Pong

Paddles, rebound angles and a beatable computer opponent.

Beginner
Breakout screenshot: rows of coloured bricks with gaps, a ball and a paddle

Breakout

Brick grids, side-aware bounces, lives and levels.

Intermediate

Free tools for game developers

Everything runs in your browser; your images never leave your computer.

All tools

Tilemap editor

Paint levels and export JSON or CSV with loader code.

Colour picker

HEX, RGB, HSL and Pygame tuples with a saved palette.

pygame or pygame-ce?

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.

Read the full comparison

pygamepygame-ce
Installpip install pygamepip install pygame-ce
Latest release2.6.1 (September 29, 2024)2.5.8 (August 9, 2026)
Prebuilt wheels forPython 3.6–3.13Python 3.10–3.14
Import namepygamepygame

Supported operating systems

Prebuilt packages exist for the three major desktop systems, so pip installs Pygame without a compiler on supported Python versions.

Common questions

Is Pygame free?

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.

Is Pygame good for beginners?

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.

Which Python version should I use?

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.

Can Pygame make 3D games?

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.

Can I sell a game made with Pygame?

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.

Does Pygame run on phones or in a browser?

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.

Make something playable today

Install Pygame, open the first tutorial and have a window on screen in ten minutes, or start in the browser right now.

↑ ↓ to moveEnter to openEsc to close