Breakout
Bounce the ball off your paddle to clear the bricks. Move with the left and right arrow keys.
Build and run 2D Python games in your browser.
Click or tab to the game to use your keyboard
Bounce the ball off your paddle to clear the bricks. Move with the left and right arrow keys.
Collect food and grow without hitting a wall or your tail. Steer with the arrow keys and press R to restart.
Fit falling pieces together to clear full rows. Use the arrow keys to move and rotate, Space to drop, and R to restart.
Play against the computer. Move your paddle with Up and Down, and press R to reset the score.
.py file. When your script uses import pygame, Python Playground loads Pygame CE automatically.pygame.display.set_mode() opens a canvas in the Game tab. While playing, click the canvas or tab to it so the game can receive keyboard input.The code below opens a 640 × 480 canvas and draws one frame. In a game loop, call pygame.display.flip() after drawing each frame to show the changes.
import pygame
pygame.init()
screen = pygame.display.set_mode((640, 480))
screen.fill("#101b33")
pygame.display.flip()
Python Playground runs Pygame CE 2.4.1 in a browser tab with SharedArrayBuffer support.
| Feature | Support in Python Playground |
|---|---|
| 2D graphics | The Game tab shows a software display. You can use pygame.SCALED and pygame.RESIZABLE. |
| Canvas size | Up to 1280 × 1280 pixels. |
| Input | Keyboard, mouse, touch, and up to two gamepads that the browser recognizes. |
| Sound | PCM WAV and browser-supported OGG sound effects. One background music track in a format your browser can decode. |
| Debugger | Set breakpoints, step through code, and inspect Variables. The last drawn frame stays visible in Game while paused. |
| OpenGL and desktop windows | Unavailable in the browser editor. |
Check Output for a Python error. If the script is running, make sure it draws to the surface returned by pygame.display.set_mode() and calls pygame.display.flip() or pygame.display.update() after drawing.
Use Upload files in the Files panel to add your Python files and assets. In your code, use the uploaded filenames, such as pygame.image.load("player.png") and pygame.mixer.Sound("jump.wav"). If your code used paths like assets/player.png, update them to match the names in Files. Then open the Python file that starts the game and click Run.
Click inside the canvas where you're playing. The game receives arrow keys while that canvas has keyboard focus.
The four examples need a physical keyboard. If you're writing a game for phones, you can draw on-screen controls and respond to Pygame touch events such as FINGERDOWN.
Open Manage Packages, remove the pygame-ce entry, save, and run again. The editor loads its supported version automatically. If you want to keep the entry, set the version to 2.4.1 or latest.
Yes. You can run and debug the examples and your own Pygame games for free, with no account required.