0 XP
Chapter 6

Your First Window

Open a game window — the first step to any game!

Core Concept

pygame.display.set_mode() creates a window. The game loop keeps it running.

Theory

Every pygame game has 3 parts: 1. Init — start pygame 2. Game loop — run forever until quit 3. Quit — clean up import pygame, sys pygame.init() screen = pygame.display.set_mode((800, 600)) clock = pygame.time.Clock() while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit(); sys.exit() screen.fill((20, 10, 40)) # dark purple pygame.display.flip() clock.tick(60)

Live Demo — Run & Explore

Try it live
Loading...

Output will appear here…

Exercise 1 / 1

📝 Create a window of size 800x500 with a dark blue background (0, 10, 40) and title 'My Game'.

Your solution
Loading...

Output will appear here…

If / Else Decisions
Drawing Shapes