</>HAND ME MY PC

Pygame · Window and game loop

Install and hello window

Pygame setup

Install with pip install pygame. Init the library, create a display surface, set a caption, and quit cleanly when the player closes the window.

``python

import pygame

pygame.init()

screen = pygame.display.set_mode((800, 600))

pygame.display.set_caption("HAND ME MY PC — Pygame")

running = True

while running:

for event in pygame.event.get():

if event.type == pygame.QUIT:

running = False

screen.fill((20, 24, 36))

pygame.display.flip()

pygame.quit()

``

Practice checkpoints

Quick quiz

pygame.display.set_mode creates…

Next lesson