You have to set a flag and fill the screen every frame. Currently you are only filling the screen on the frame that a mouse button is down and the mouse is in collision with your student rect.
Here is an example that when you press a mouse button it switches to and from white.
Here is an example that when you press a mouse button it switches to and from white.
import pygame as pg pg.init() screen = pg.display.set_mode((800,600)) running = True bg_white = False while running: for event in pg.event.get(): if event.type == pg.QUIT: running = False elif event.type == pg.MOUSEBUTTONDOWN: bg_white = not bg_white if bg_white: screen.fill((255,255,255)) else: screen.fill((0,0,0)) pg.display.update()
Recommended Tutorials: