Ok so i have this snake game that i made using pygame its very basic and it works but i created a login program that i need to rund the game from and whenever i try to close the game i get a error that looks like this The thing is that when i tried putting sys.exit() after the pygame.exit() in the snake code my login program closes and just runs a blank python window:
Traceback (most recent call last):
File "C:\Users\test\Desktop\Summative\LukaLogin.py", line 119, in Snake
snake = snakeSummative.main()
File "C:\Users\test\Desktop\Summative\snakeSummative.py", line 178, in main
playAgain(final)
File "C:\Users\test\Desktop\Summative\snakeSummative.py", line 161, in playAgain
for event in pygame.event.get():
pygame.error: video system not initialized
Snake Game:
def playAgain(final):
gameDisplay.fill(WHITE)
username = 'luka'
message_to_screen("Game Over, press c to play again press q to quit", RED)
message_to_screen1(str(final),GREEN)
file = open('Scores.txt','a')
file.write( username + ' ' + 'Snake' + ' ' + str(final) + ' ' + '\n')
pygame.display.update()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_c:
score = 0
return True
if event.key == pygame.K_q:
pygame.quit()
break
def main():
while True:
final = gameLoop()
playAgain(final)
pygame.quit()
quit()
if __name__ == '__main__':
main()
Login def that calls the snake game:
class GameHub(QtGui.QMainWindow,Ui_GameHub):
def __init__ (self):
QtGui.QMainWindow.__init__(self)
self.setupUi(self)
self.play_BlackJack.clicked.connect(self.BlackJack)
self.play_Snake.clicked.connect(self.Snake)
self.play_Scores.clicked.connect(self.HighScores)
self.play_Logout.clicked.connect(self.LogOut)
def Snake(self):
import snakeSummative
snake = snakeSummative.main()
Any help would be apreciated im really stumped to as why i get the error even though i break the loop