why wont pygame quit?

2.2k views Asked by At

The game freezes instead of quitting. I have to exit from Idle. Any ideas on what to do?

def quit_game():
    for event in pygame.event.get():

        if event.type == pygame.QUIT:

            sys.exit()
quit_game()
2

There are 2 answers

3
JamesWat On

This is an IDLE bug. I would recommend using a real IDE such as pycharm. However to fix this issue, have a look at the pygame FAQ. They offer this solution:

# ... running = True
while running:
    event = pygame.event.wait ()
    if event.type == pygame.QUIT:
        running = False  # Be IDLE friendly
pygame.quit ()
0
Chhaya Vankhede On

It may work....

def quit_game():
        for event in pygame.event.get():

            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()
    quit_game()