问题描述
我在pygame中打开png时遇到问题。 我找到了其他建议使用相对路径的建议,但仍然无法使用。 还有什么我可以尝试的吗?
我正在使用Python 3.7.9
这是我的代码:
import pygame
import os
current_path = os.path.dirname(__file__)
resource_path = os.path.join(current_path,'resources')
image_path = os.path.join(resource_path,'images')
pygame.init()
screen = pygame.display.set_mode((800,600))
pygame.display.set_caption('Space Invaders')
icon = pygame.image.load(os.path.join(image_path,'ufo.png'))
pygame.display.set_icon(icon)
running = True
# Game Loop
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
这是错误消息:
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
File "D:\Github\PyGame Lessons\Space Invader\venv\main.py",line 15,in <module>
icon = pygame.image.load(os.path.join(image_path,'ufo.png'))
pygame.error: Couldn't open D:\Github\PyGame Lessons\Space Invader\venv\resources\images\ufo.png
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)