我刚刚在 mac osx 10.11.1 上的 python 3.5 上使用 pygame 的第一步。我认为我已经正确安装了 pygame 因为当我运行
import pygame
它接受它。我正在对基本 pygame 使用进行一些测试,并且 pygame.display.set_mode 有问题 这是代码:
import pygame
pygame.init()
screen = pygame.display
screen.set_mode((720,480))
它运行正常,没有任何错误,但打开的 pygame 屏幕(与 IDLE 屏幕不同)它卡住了。光标变成了旋转的彩虹状物体。
对不起,如果这是一个非常愚蠢的问题,但我对此真的很陌生,我已经搜索了一整天,但找不到类似的东西。
感谢您的宝贵时间
最佳答案
您需要编写一个事件循环和一个退出事件,因为用户无法关闭窗口。 对于事件循环我会做类似的事情:
running = True
while running: # This would start the event loop
for event in pygame.event.get():
if event.type == pygame.QUIT: # This would be a quit event.
running = False # So the user can close the program
screen.fill(0,0,0) # This fills the screen with black colour.
pygame.display.flip() # This "flips" the display so that it shows something
pygame.quit()
我希望这有帮助!事件循环只是让程序保持运行的东西,没有它,代码看起来会很困惑,所以最好有一个。
关于python - pygame.display.set_mode 窗口打开但卡住 python 3.5 mac osx 10.11.1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34147302/