Purple Hat – Games & GUI
advanced35 XP
Pygame Basics
Create a game window, draw shapes, and handle keyboard input
Pygame Basics
Python
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((0,0,0))
pygame.draw.circle(screen, (50,100,220), (400,300), 40)
pygame.display.flip()
clock.tick(60)⌨️
Type it yourself
Don't just read it — type the example from above into the box, press Run ▶, and watch what happens. Typing it yourself is how it really sticks! Stuck? Tap Show example.
Python · Playground
Output
Press ▶ Run to see your code come to life…Quick check
01/2
What are the three main steps of a game loop?