Pygame window can not be closed on a Mac problem

Viewed 617

I have made a python program that uses Pygame. For some reason, I can't close the window when pressing the red cross. I tried using Command+Q but it doesn't work as well. I have to quit idle (my python interpreter) to close the window. Is there any other way to make the window close by pressing the red 'x' at the top right-hand corner?

My code:

import pygame
import sys
from pygame.locals import *

pygame.init()
screen = pygame.display.set_mode((800,800))
while 1:     
    pygame.display.update()
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
3 Answers

A pygame window can be closed properly if you use a different python interpreter. Try using pycharm, you can close pygame windows using pycharm.

You should just force quit the window or run another program to close the window. When you run a different program, the window should close.

Try this:

import pygame, sys
from pygame.locals import *

pygame.init()
screen = pygame.display.set_mode((800,800))
while True:     
    pygame.display.update()
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()
Related