I'm trying to make a program that toggles the background color from black to white when I press the space bar.
Does anyone know what is wrong with my code:
import pygame, sys
clock = pygame.time.Clock()
wn_size = (800, 600)
pygame.init()
screen = pygame.display.set_mode(wn_size)
bg_change = False
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
if bg_change:
bg_change = True
else:
bg_change = False
if bg_change == True:
screen.fill(255,255,255)
else:
screen.fill((0, 0, 0))
pygame.display.update()
clock.tick(60)