turtle.bgpic()导致Tk异常

时间:2014-12-07 06:43:45

标签: python-3.x

第一年的CS学生在这里,我正在研究的一个项目在尝试为Turtle窗口设置背景图片时因一个看似简单的错误而停滞不前:

此:

def test():
    turtle.bgpic("image.gif")

始终如一地回归:

Traceback (most recent call last):
  File "C:\Users\Wesley\Desktop\RISK.py", line 17, in <module>
    createGameMap()
  File "C:\Users\Wesley\Desktop\RISK.py", line 7, in createGameMap
    t.bgpic("Risk01.gif")
  File "C:\Python 3.4.2\lib\cTurtle.py", line 2564, in bgpic
    return self.getScreen().bgpic(picname)
  File "C:\Python 3.4.2\lib\cTurtle.py", line 1012, in bgpic
    self._setbgpic(self._bgpic, self._bgpics[picname])
  File "C:\Python 3.4.2\lib\cTurtle.py", line 532, in _setbgpic
    self.cv.itemconfig(item, image=image)
  File "<string>", line 1, in itemconfig
  File "C:\Python 3.4.2\lib\tkinter\__init__.py", line 2416, in itemconfigure
    return self._configure(('itemconfigure', tagOrId), cnf, kw)
  File "C:\Python 3.4.2\lib\tkinter\__init__.py", line 1310, in _configure
    self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
_tkinter.TclError: image "pyimage2" doesn't exist

请帮我解决这个错误,我完全无法解释甚至开始排除故障。

1 个答案:

答案 0 :(得分:0)

看起来你正在使用图像的相对参考,是&#34; image.gif&#34;与 - &gt;在同一目录中&#34; C:\用户\韦斯利\桌面\ RISK.py&#34;你的Risk.py文件?