enrique2334
enrique2334

Reputation: 1059

Why does the pygame window not close properly?

When I go to close the program window, the program freezes, then I am forced to force quit the program. Why doesn't the program close when the X / Close button is clicked on. I am also using python 2.7 if that matters.

import pygame
import os, sys
from itertools import *
from oryxsprites import *
from oryxbackground import *

running = True


while running:

    backgroundmain()
    pygame.display.set_caption('OryxGame')
    #pygame.display.set_icon(biggrasstile)

    for event in pygame.event.get():
         if event.type == pygame.QUIT:
             running = False

Upvotes: 5

Views: 8567

Answers (2)

Eric Poirier
Eric Poirier

Reputation: 11

With Python 3.2, pygame 1.9 win32, sys.exit() is useless (seen on an online tuto). pygame.quit() works perfectly

Upvotes: 1

Elliot Bonneville
Elliot Bonneville

Reputation: 53291

A quote from an article that sports code very similar to yours:

The window now persists whilst 'running' is equal to True, which it will be until you close the window (by clicking the X). Note that if you use an IDE for Python programming, then it may interfere with Pygame. This isn’t normally a major problem but it can stop the Pygame window from closing properly. If so, adding pygame.quit() should solve the problem.

Upvotes: 5

Related Questions