首页 > 解决方案 > 我在 pygame 中上传图像时遇到问题

问题描述

因此,我目前正在尝试与我的编码班的其他成员一起制作视频游戏,但在 pygame 中上传图像时遇到了问题。这是这里的代码

import pygame
pygame.init()
white = (255,255,255)
X = 400
Y = 400
display_surface = pygame.display.set_mode((X, Y ))
pygame.display.set_caption('Image')
image = pygame.image.load("BootLeg.jpg") 
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()`enter code here`
pygame.display.update()

标签: pygame

解决方案


如果BootLeg.png与您的 python 文件不在同一个文件夹中,它将无法工作。

image = pygame.image.load("folder/BootLeg.png")

如果这仍然不起作用,请尝试这样做:

image = pygame.image.load(os.path.join("folder", "BootLeg.png"))


推荐阅读