python - Pygame 窗口在退出时卡住

标签 python pygame

我是 python 的新手,也是 pygame 的新手。我正在尝试使用 pygame。所有程序似乎都运行良好,除非我尝试退出。窗口卡住(“应用程序无响应”),我不得不强制退出它。我正在使用 OSX、python 3.6,如果重要的话,我会通过 sublime text 运行它。代码如下:

import pygame
done = False
size = (400,400)
screen = pygame.display.set_mode(size)

while done==False:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.display.quit()
            pygame.quit()
            done = True

pygame.display.quit()
pygame.quit()

感谢您的帮助!

最佳答案

试试这个,它对我有用:

import sys
import pygame

size = (400,400)
screen = pygame.display.set_mode(size)

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

关于python - Pygame 窗口在退出时卡住,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52846063/

相关文章:

javascript - 如何使用两个列表中的数据创建 Chart.js 散点图

python - 在全息 View 中设置各个元素的选项

Pygame如何改变表面的大小?

python - 将 unicode 字符串转换为十六进制表示

python - 具有距离条件的最近邻加入

python - SQLAlchemy 按字段排序()

python - 重力强度和跳跃高度在某种程度上取决于帧速率 - Pygame

Python Pygame 按两个方向键和另一个键射击没有子弹

Python 方波函数 - 这是怎么回事?