我正在尝试使用 pythonw 运行 pygame 程序以避免显示控制台窗口。这会导致与打印语句相关的奇怪问题。
基本上,程序将在几秒钟后退出,没有错误消息。我打印的越多,它发生的越快。如果我在空闲或在命令提示符下(或在 linux 中)运行它,程序运行良好。此问题仅在使用 pythonw 启动时发生(右键单击、打开方式、pythonw)。
我在 Windows XP 32 位上使用 python 2.7.11。pygame 1.9.1 发布。
有解决方法吗?为什么程序简单地终止而没有错误?
import pygame
from pygame.locals import *
succeeded, failed = pygame.init()
display_surface = pygame.display.set_mode((320, 240))
clock = pygame.time.Clock()
terminate = False
while terminate is False:
for event in pygame.event.get():
if event.type == QUIT:
terminate = True
area = display_surface.fill((0,100,0))
pygame.display.flip()
elapsed = clock.tick(20)
print str(elapsed)*20
pygame.quit()