Pygame Web IDE
Loading Environment...
Save Online
Online Projects
DL .py
DL .html
Pop Out
Clear
Stop
Run Code
main.py
import asyncio import pygame import sys # Initialize pygame.init() WIDTH, HEIGHT = 400, 400 screen = pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption("My Web Pygame") clock = pygame.time.Clock() async def main(): running = True x, y = 200, 200 while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False return # Simple movement keys = pygame.key.get_pressed() if keys[pygame.K_LEFT]: x -= 5 if keys[pygame.K_RIGHT]: x += 5 if keys[pygame.K_UP]: y -= 5 if keys[pygame.K_DOWN]: y += 5 screen.fill((20, 20, 30)) pygame.draw.circle(screen, (50, 150, 255), (x, y), 20) pygame.display.update() # CRITICAL: Yield to browser await asyncio.sleep(0) clock.tick(60) # Start the asyncio loop asyncio.ensure_future(main())
Console Output
Save Project Online
Enter a name for your Pygame project to save it to the database.
Cancel
Save Project
Online Projects
×
Loading projects...