当我去关闭程序窗口时,程序卡住了,然后我被迫强制退出程序。为什么单击 X/关闭按钮时程序没有关闭。 如果重要的话,我也在使用 python 2.7。
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
最佳答案
引自 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.
关于python - 为什么 pygame 窗口不能正常关闭?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10694480/