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…
Ask AI Tutor
AI Tutorgemini-3.1-flash-lite-preview
AI
Hi! I'm your AI tutor for Your First Window. 🎓
Ask me anything about this lesson — what a variable is, why loops are useful, or "why is my code not working?". I'm here to help you understand, not just give you answers!
What's on your mind? 😊