PyGame显示黑屏,即使缩进是正确的



我正在学习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()

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

我尝试删除图标,它对我有效(我认为你需要使用.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()

最新更新