Having researched this for hours, I cannot figure out why this error is being triggered. Here is the entire message:
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
File "snake.py", line 37, in <module>
redraw_window()
File "snake.py", line 23, in redraw_window
win.fill((0, 0, 0))
pygame.error: display Surface quit
When I run the program, the window opens and closes instantly. I'm running Python v3.7 via a conda virtual environment. And here is my code:
import pygame
pygame.init()
#----------------------------
# CONSTANTS
#----------------------------
window_width = 256
window_height = 256
win = pygame.display.set_mode((window_width, window_height))
pygame.display.set_caption('Snake Game')
#----------------------------
# CLASSES
#----------------------------
#----------------------------
# REDRAW WINDOW
#----------------------------
def redraw_window():
win.fill((0, 0, 0))
pygame.display.update()
#----------------------------
# MAIN GAME LOOP
#----------------------------
running = True
while running:
# listen for window closure
for event in pygame.event.get():
if event.type == pygame.quit():
run = False
redraw_window()
pygame.quit()
I even tried passing 'win' into the redraw_window function and that changed nothing.