Python – Pygame window gets stuck on exit

Pygame window gets stuck on exit… here is a solution to the problem.

Pygame window gets stuck on exit

I’m new to Python and new to Pygame. I’m trying to use pygame. All programs seem to work fine unless I try to quit. The window stuck (“app not responding”) and I had to force quit it. I’m using OSX, python 3.6, and I’ll run it via sublime text if it’s important. The code is as follows:

import pygame
done = False
size = (400,400)
screen = pygame.display.set_mode(size)

while done==False:
    for event in pygame.event.get():
        if event.type == pygame. QUIT:
            pygame.display.quit()
            pygame.quit()
            done = True

pygame.display.quit()
pygame.quit()

Thanks for your help!

Solution

Try this, it worked for me :

import sys
import pygame

size = (400,400)
screen = pygame.display.set_mode(size)

while True:
    for event in pygame.event.get():
        if event.type == pygame. QUIT:
            pygame.quit()
            sys.exit()

Related Problems and Solutions