python - 为什么 pygame 窗口不能正常关闭?

标签 python pygame

当我去关闭程序窗口时,程序卡住了,然后我被迫强制退出程序。为什么单击 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/

相关文章:

python - 将数据从文本框发送到 Flask?

python - 解析文本文件中的值

python - 交互式 IPython 终端中连续运行的 Tensorflow Op 命名

python - 通过使用 Python 修改 Excel 后面的 xml 来动态更改 Excel 中的文件共享根目录

python - 如何根据窗口大小缩放图像?

python - Pygame,OpenGL : Project 3D rgb values to 2D surface

Python 写 MIDI 文件

python - 如何在 tkinter 应用程序中设置 Tab 键顺序?

python - 在pygame中绘制到 Sprite 的表面

python - Pygame Sprite 不会重置