import pygame # Homework: change the background color by pressing keys. # - Pressing R should change the background to red. # - Pressing G should change the background to green. # - Pressing B should change the background to blue. # Hint: store the current color in a variable and update it on KEYDOWN events. # pygame.K_r, pygame.K_g, pygame.K_b are the key constants. pygame.init() screen = pygame.display.set_mode((640, 480)) pygame.display.set_caption("Key Color") # TODO: define your color variables and a starting background color variable # 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: pass # TODO: replace pass with your key checks # TODO: fill with bg_color instead of a fixed color screen.fill((30, 30, 30)) pygame.display.flip() pygame.quit()