I have a Python script that amongst other things opens a pygame window at one point. If this window is closed it can be reopened. If the pygame window gets opened again I get a pygame.error: display Surface quit
in the background. Everything works perfectly fine, I can just see all the errors when I finally quit the parent script.
parent.py:
from game import game
def launch_game():
game = Game() # Now I am in the pygame window until I quit it
# Do a bunch of other stuff
# At some point
launchGame()
game.py
class Game():
def __init__(self):
pygame.display.init()
self.screen = pygame.display.set_mode((640, 480))
# Set up a bunch of GPIO Controls including a quit button
self.playing = True
while self.playing:
self.check_events()
sleep(.1)
pygame.quit()
def check_events(self, current_station):
if GPIO.input(self.quitButton) == 0:
self.playing = False
if GPIO.input(self.upButton) == 0:
self.playing = moveUp()
if GPIO.input(self.downButton) == 0:
self.playing = moveDown()
So the first time I launchGame() happens everything works fine. The next time I start seeing the display Surface quit in the background.
One error for every time I hit one of the other buttons . The moveUp() and moveDown() functions both end with screen drawing function and that starts with self.screen.fill(bg_color)
this is what is throwing the error.
If I open can close the game twice, I get two error message per button push, three times, three error messages. It is like the screen objects are still being kept in memory somewhere even after the pygame.quit()
is called.