Search code examples
pythonmacospygameanacondasublimetext3

Pygame screen dosen't close


I'm a Macbook user and I have just recently started learning programming games using python. my issue is that every time I try to close the screen it doesn't close.

import pygame
import sys
pygame.init()
width = 800
hight = 600
screen = pygame.display.set_mode((width , hight))
game_over= False
while not game_over:
    for event in pygame.event.get(): 
           if event.type == pygame.QUIT :
               sys.exit()

When I point the cursor to the screen it turns to a circle... Cursur, so usually I just press force to quit "on the snake icone" in the dock So how can I fix this and make the screen close just by pressing the close button ? I'm using python 3. Thank you.


Solution

  • Full edited and tested code :

    import pygame
    import sys
    pygame.init()
    width = 800
    hight = 600
    running = True
    screen = pygame.display.set_mode((width , hight))
    
    while running:
        for event in pygame.event.get(): 
               if event.type == pygame.QUIT :
                   pygame.quit()
                   sys.exit()
    

    Test on Linux mint with visual studio code. Tested more than 5 times. Expected results.