【问题标题】:pygame.display.set_mode Window opens but freeze python 3.5 mac osx 10.11.1pygame.display.set_mode 窗口打开但冻结 python 3.5 mac osx 10.11.1
【发布时间】:2016-03-12 20:47:28
【问题描述】:

我只是在 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 屏幕不同)它冻结了。光标变成了这个旋转的彩虹东西。

对不起,如果这是一个非常愚蠢的问题,但我真的很陌生,我整天都在搜索,找不到类似的东西。

感谢您的宝贵时间

【问题讨论】:

    标签: python macos pygame freeze python-3.5


    【解决方案1】:

    您需要编写一个事件循环和一个退出事件,因为用户无法关闭窗口。 对于事件循环,我会这样做:

    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()
    

    我希望这会有所帮助!事件循环只是保持程序运行的东西,没有它,代码看起来会很混乱,所以最好有一个。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-02-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-25
      • 2013-01-07
      • 1970-01-01
      相关资源
      最近更新 更多