pygame窗口总是灰色

时间:2019-12-01 10:51:18

标签: python pygame

我正在尝试用红色填充窗口,但我得到的只是一个灰色屏幕。无论我做什么(添加图片等),它只会显示灰色屏幕。声音有效,但我无法获取图像等。无法确定它在其他人的计算机上是否有效。

import pygame 

#initilize pygame 
pygame.init()

#create the screen
screen = pygame.display.set_mode((800,600))


#title and icon
pygame.display.set_caption("uzay gemisi")
icon = pygame.image.load("ufo.png")
pygame.display.set_icon(icon)


#game loop
running  = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    #rgb red green blue
    screen.fill((255, 0, 0))
    pygame.display.update()




1 个答案:

答案 0 :(得分:0)

您的代码对我而言似乎工作正常(删除2条图标行时)。但是,要关闭窗口,您需要在事件处理程序中运行= False之后的行添加pygame.quit()。