I've made a menu screen where clicking on a button leads to a different screen in the same window.
def main():
import pygame, random, time
pygame.init()
size=[800, 600]
screen=pygame.display.set_mode(size)
pygame.display.set_caption("Game")
done=False
clock=pygame.time.Clock()
while done==False:
for event in pygame.event.get():
pos = pygame.mouse.get_pos()
if event.type == pygame.QUIT:
done=True
break
if button_VIEW.collidepoint(pos):
if event.type == pygame.MOUSEBUTTONDOWN:
print("VIEW.")
view()
break
screen.fill(black)
...
def view():
done=False
clock=pygame.time.Clock()
while done==False:
for event in pygame.event.get():
pos = pygame.mouse.get_pos()
if event.type == pygame.QUIT:
done=True
break
...
If possible, I'd like to know how I can avoid the error:
screen.fill(black)
error: display Surface quit
>>>
After looking at other questions on here, I tried adding break
s to the exits of any loops, but still the error occurs.
I understand the issue is that the program is trying to execute screen.fill(black)
after the window has been closed, but I have no further ideas on how to prevent the error.
I appreciate any help. Sorry if it seems simple.