首页 > 解决方案 > 无法通过 Pygame 的 Image.load() 打开图像

问题描述

我的 pygame 程序似乎没有加载图像。我通过直接输入图像路径以及加入目录来尝试 image.load() 。我在 Sublime Text 和 IDLE 上尝试了代码。文件来源:C:\Users\Aich\Documents\PythonProjects\Trial 图片来源:C:\Users\Aich\Desktop\Sprite1.png (我目前将图像和文件保存在不同的位置,但没有将它们保存在同一位置产生任何东西)

我正在使用 Windows 8.1。

import pygame
pygame.init()
white = (255, 255, 255)

x = 500
y = 400

display_surface = pygame.display.set_mode((x,y))

pygame.display.set_caption('Image')

image = pygame.image.load(r'C:\Users\Aich\Desktop\Sprite1.png').convert()

while True:
    display_surface.fill(white)
    display_surface.blit(image , (0,0))

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

    pygame.display.update()

标签: python-3.xpygame-surface

解决方案


推荐阅读