问题是您不处理pygame的事件队列。您应该
pygame.event.pump()在循环结束时简单调用,然后您的代码才能正常工作:
...while not done: clock.tick(60) keyState = pygame.key.get_pressed() if keyState[pygame.K_ESCAPE]: print('nGame Shuting Down!') done = True pygame.event.pump() # process event queue从文档(重点是我的):
pygame.event.pump()
内部处理pygame事件处理程序
pump() -> None_对于游戏的每一帧,您都需要对事件队列进行某种调用。
这样可以确保您的程序可以与操作系统的其余部分进行内部交互。_如果您没有在游戏中使用其他事件函数,则应调用pygame.event.pump()以允许pygame处理内部动作。如果您的程序通过其他pygame.event函数持续处理队列中的事件,则不需要此函数。
事件队列内部必须处理一些重要的事情。主窗口可能需要重新粉刷或响应系统。 如果您对事件队列的调用时间过长,系统可能会确定您的程序已锁定 。
Note that you don’t have to do this if you just call
pygame.event.get()
anywhere in your main-loop; if you do not, you should probably call
pygame.event.clear()so the event queue will not fill up.



