【问题标题】:pygame display's a black screen even though indentation is correct即使缩进正确,pygame显示黑屏
【发布时间】:2020-03-28 08:40:57
【问题描述】:

我正在学习 pygame,但我不确定它为什么只给我一个黑屏。我已经确认缩进是正确的。我的代码:

import pygame

pygame.init()

screen = pygame.display.set_mode((800, 600))

pygame.display.set_caption('Space Invaders')
icon = pygame.image.load('ufo.png')
pygame.display.set_icon(icon)

running = True

while running:
    screen.fill((255,255,0))

    for event in pygame.event.get():
      if event.type == pygame.QUIT:
        running = False

    pygame.display.update()

我看不出这个程序有什么问题,现在我很困惑。

【问题讨论】:

  • 试试pygame.display.flip()
  • pygame.display.flip() 的行为也没有变化。它仍然显示黑屏。
  • 刚刚安装了pygame==2.0.0.dev6,它可以工作了!

标签: python-3.x pygame


【解决方案1】:

我尝试删除图标,它对我有用(我认为您需要使用 .ico 文件而不是 .png)

import pygame

pygame.init()

screen = pygame.display.set_mode((800, 600))

pygame.display.set_caption('Space Invaders')

running = True

while running:
    screen.fill((255,255,0))

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    pygame.display.update()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-18
    相关资源
    最近更新 更多