【发布时间】:2012-07-14 23:16:53
【问题描述】:
我正在学习使用 Pygame,当我使用 sys.exit() 时,我遇到了问题。代码如下:
import pygame, sys,os
from pygame.locals import *
pygame.init()
window = pygame.display.set_mode((468, 60))
pygame.display.set_caption('Game')
screen = pygame.display.get_surface()
file_name = os.path.join("data","image.bmp")
surface = pygame.image.load(file_name)
screen.blit(surface, (0,0))
pygame.display.flip()
def input(events):
for event in events:
if event.type == QUIT:
sys.exit(0)
else:
print event
while True:
input(pygame.event.get())
这实际上只是 pygame 教程中的代码。当我实际尝试退出时会出现问题,无论我尝试对sys.exit() 使用什么事件。
Traceback (most recent call last):
File "C:/Python27/Lib/site-packages/pygame/examples/test.py", line 25, in <module>
input(pygame.event.get())
File "C:/Python27/Lib/site-packages/pygame/examples/test.py", line 20, in input
sys.exit(0)
SystemExit: 0
... 然后程序不退出。我在这里做错了什么?因为我确实注意到这段代码是针对 Python 的过时版本的。
【问题讨论】: