Pyglet文件名“找不到资源”

时间:2014-02-12 12:28:37

标签: python tkinter pyglet

我正在尝试打开音乐曲目并将其添加到Pyglet中的播放器队列中。

    def QueueAudio(self):
        self.musicpath=filedialog.askopenfilename()
        print(self.musicpath)
        Player.queue(pyglet.resource.media(r"self.musicpath"))

当print语句打印文件名时,musicpath变量工作正常。当玩家尝试排队赛道时会出现错误。错误如下。

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Python33\lib\site-packages\pyglet\resource.py", line 605, in media
    location = self._index[name]
KeyError: 'self.musicpath'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Python33\lib\tkinter\__init__.py", line 1475, in __call__
    return self.func(*args)
  File "C:\Users\Rob\Google Drive\Coursework\Part 2\music player tests\test5.py", line 99, in QueueAudio
    self.playerpath=pyglet.resource.media(r"self.musicpath")
  File "C:\Python33\lib\site-packages\pyglet\resource.py", line 615, in media
    raise ResourceNotFoundException(name)
pyglet.resource.ResourceNotFoundException: Resource "self.musicpath" was not found on the path.  Ensure that the filename has the correct captialisation.

有谁知道为什么会这样,有什么可以修复它?

1 个答案:

答案 0 :(得分:0)

这条线看起来是罪魁祸首:

self.playerpath=pyglet.resource.media(r"self.musicpath")

当您传递名为"self.musicpath"的变量的内容时,您正在将字符串self.musicpath传递给函数。你需要这样称呼它:

self.playerpath = pyglet.resource.media(self.musicpath)