Python Projects & Skills / Games
Lesson 9 of 28
Intro to pygame
pygame lets you make 2D games with a window, images, sound and keyboard input. Every game runs a loop: handle input, update, draw.
Key points
- pip install pygame
- The game loop runs ~60 times a second
- clock.tick(60) limits the speed
import pygame
pygame.init()
screen = pygame.display.set_mode((640, 480))
clock = pygame.time.Clock()
running = True
while running:
for e in pygame.event.get():
if e.type == pygame.QUIT:
running = False
screen.fill((10, 16, 32))
pygame.display.flip()
clock.tick(60)Quiz · +10 XP
What are the three steps of a game loop?
Log in to save progress and earn XP.