【问题标题】:Pygame window does not open via python launcherPygame 窗口无法通过 python 启动器打开
【发布时间】:2020-04-07 12:00:10
【问题描述】:

'''代码''' #!/Library/Frameworks/Python.framework/Versions/3.8/bin/python3 导入pygame 从 pygame.locals 导入 *

pygame.init()

screen = pygame.display.set_mode((800,800))
pygame.display.set_caption("Space Invaders")


while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()

【问题讨论】:

  • 使用mac osx系统

标签: python macos pygame


【解决方案1】:

试试这个:

pygame.init()

screen = pygame.display.set_mode((800,800))
pygame.display.set_caption("Space Invaders")


while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()

    screen.fill((0, 0, 0))
    pygame.display.update()

【讨论】:

    【解决方案2】:

    这应该可行。

    import pygame
    pygame.init()
    
    screen = pygame.display.set_mode((800,800))
    pygame.display.set_caption("Space Invaders")
    
    
    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
    
        pygame.display.update()
    

    您必须导入 pygame,更改 if event.type == QUIT: if event.type == pygame.QUIT:,并使用 pygame.display.update() 更新屏幕

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-29
      • 1970-01-01
      相关资源
      最近更新 更多