使用Importlib Pygame打开资源文件时无法打开

时间:2019-02-03 13:41:25

标签: python python-3.x pygame python-importlib

我有一个python菜单,它将打开其他包含游戏的程序。 每当我尝试使用importlib打开其中一款游戏时,声音或背景图像之类的资源都无法打开。

打开游戏程序:

spec = importlib.util.spec_from_file_location(game+".py", "{}/{}/{}.py".format(path,game,game))
foo = importlib.util.module_from_spec(spec)
spec.loader.exec_module(foo)
foo.MyClass()

打开游戏程序时出错:

", line 32, in open_game
 spec.loader.exec_module(foo)
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
pygame.error: Couldn't open RunBackground.jpg

必要的游戏资源,例如“ RunBackground.jpg”位于游戏程序文件夹中。我要打开的游戏程序位于菜单的其他文件夹中。

0 个答案:

没有答案
相关问题