1

可能重复:
Pygame 程序在退出时挂起

运行这个简单的程序:

import pygame, sys

pygame.init()

screen = pygame.display.set_mode((800,600))

while True:
    #process input
    for event in pygame.event.get():
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_ESCAPE:
                sys.exit()

在 IDLE 中得到这个简单的消息:

Traceback (most recent call last):
  File "C:/Users/Aerovistae/Desktop/GD_in_class", line 12, in <module>
    sys.exit()
SystemExit

程序停止响应,必须按Ctrl+Alt+Del。我看不出我在哪里出错了,这是我所能得到的最基本的。我正在关注教授在讲座中所做的事情,我看不出我的代码和他的代码有什么区别。谁能建议可能导致问题的原因?

4

1 回答 1

5

退出pygame的正确方法是调用

pygame.quit()

在主运行循环之后。

从 pygame 文档中阅读:http://www.pygame.org/wiki/FrequentlyAskedQuestions#In IDLE 为什么 Pygame 窗口不能正确关闭?

只需退出主运行循环而不是 sys.exit() 并结束程序。

于 2012-09-05T19:19:58.890 回答