无法将图像加载到pygame显示

2024-03-28 12:10:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我的图像不会显示在屏幕上,但我没有任何错误。我查了一下,没有找到适合我的解决办法。你知道吗

代码:

import pygame

pygame.init()
sw = 500
sh = 500
win = pygame.display.set_mode((sw,sh))
fps = pygame.time.Clock()
x = (sw * 0.3)
y = (sh * 0.95)
# also tried just convert() and no convert at all
player = pygame.image.load('SH.png').convert_alpha()
white = (255, 255, 255)
def Player(x, y):
    win.blit(player, (x, y))

dead = False

run = True
while not dead:

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            dead = True
    win.fill(white)
    Player(x, y)

    pygame.display.update()
    fps.tick(60)

pygame.quit()

Tags: 图像eventtrueconvert屏幕shdisplaysw