python - pygame.display.set_mode 窗口打开但卡住 python 3.5 mac osx 10.11.1

标签 python macos pygame freeze python-3.5

我刚刚在 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/

相关文章:

python - 比较 Python 中的 C 指针

python - 如何偏移 x 轴刻度以使其他刻度稍低/略高?

python - 应用服务器的单元测试

python - 无法在 Jupyter Notebook 中导入 tensorflow

java - OS X : How to speed-up Java/Swing GUI?

c++ - 尝试在 mac osx 上编译 tcpxtract 会给出未找到的 i386 符号

python - 使用矩阵测试两个 Sprite 是否重叠

python - 使用 pip : Command "python setup.py egg_info" failed with error code 1 安装 pygame

macos - 在使用 Applescript 单击之前验证复选框

background - pygame,停止后台滚动