pygame - 我在 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()
解决方案
如果BootLeg.png
与您的 python 文件不在同一个文件夹中,它将无法工作。
image = pygame.image.load("folder/BootLeg.png")
如果这仍然不起作用,请尝试这样做:
image = pygame.image.load(os.path.join("folder", "BootLeg.png"))
推荐阅读
- html - 使用 javascript 登录登录到 Web
- c# - 电报 API 身份验证“太快”
- x-cart - 如何修复 X-cart 产品页面?产品页面为空白
- ios - 自动布局约束边界条件
- angular - Angular 7 推荐的无需访问底层源代码即可操作 DOM 的方法
- r - 箱线图上的样本量
- kdb - 对传递的参数应用每个操作的 lambda 和投影组合的代码优化
- node.js - Actions-On-Google Card 字幕未显示在模拟器或 Android 手机中
- javascript - 为我的抵押贷款计算器实施递归计算
- jquery - jQuery Ui Slider - 如何防止工具提示显示在滑块下方?