import pygame

pygame.init()

screen = pygame.display.set_mode((640, 480))
pygame.display.set_caption("Key Color")

RED   = (200,  50,  50)
GREEN = ( 50, 180,  70)
BLUE  = ( 50,  80, 200)

bg_color = (30, 30, 30)

running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_r:
                bg_color = RED
            elif event.key == pygame.K_g:
                bg_color = GREEN
            elif event.key == pygame.K_b:
                bg_color = BLUE

    screen.fill(bg_color)
    pygame.display.flip()

pygame.quit()
