# Why doesn't my pygame window close on MacOS?

I am trying to create a window and then close the window. Everything runs smoothly until I click the red X. When I click it, the window doesn't close and all that happens is that the colourful red beach ball thing shows up whenever I hover my mouse over the Pygame window and the window just does not respond.

It seems like the pygame.quit() or pygame.display.quit() functions do not work for some reason.

import pygame
pygame.init()
Window=pygame.display.set_mode((250, 250))
run=True
while run:
for event in pygame.event.get():
if event.type==pygame.QUIT:
run=False
pygame.quit()
pygame.display.quit()


• In the future, please post code as text instead of images. That way people can quickly try to reproduce your issue. – Tyyppi_77 Dec 30 '18 at 11:35
• Try to draw something like a coloured background to the window, also, Why are you using pygame.display.quit()? pygame.quit() alone would do the work. – Juanpa Dec 30 '18 at 19:54

This is the correct code:

from pygame.locals import *

import sys,pygame

screen=pygame.display.set_mode((200, 100))

pygame.display.set_caption("hello")

while(True):

for event in pygame.event.get():

if event.type==QUIT:

pygame.quit()

sys.exit()

• Why is that the correct code? What's missing in the OPs implementation? – Vaillancourt Aug 19 '19 at 20:03

Well instead of declaring run as variable you can just do it like this:

from pygame.locals import *
import sys


enter code here

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

• This doesn't seem to answer the question, but just points out an unrelated thing. – user1118321 Mar 30 '19 at 15:42
• Welcome to GDSE & thanks for contributing. As mentioned, this doesn't seem to address OP's core problem & as such it seems more like a comment than an answer. There is a small rep limit before you can comment, but attempting to get around that by posting as answer rarely works out well. If you did intend this more as a comment than a stand alone solution to the problem, flag your answer with a brief explanation for the mods. – Pikalek Apr 1 '19 at 4:55