我只是在 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()
希望对您有所帮助!事件循环只是让程序保持运行的东西,没有它,代码看起来会很困惑,所以最好有一个。
