我想我的圖像設置爲一個文件,但是當我運行它,我得到我怎麼設置龜的圖像
Exception in Tkinter callback Traceback (most recent call last):
File "C:\Users\Travi\AppData\Local\Programs\Python\Python36-32\lib\tkinter__init__.py", line 1699, in call return self.func(*args) File "C:\Users\Travi\AppData\Local\Programs\Python\Python36-32\lib\turtle.py", line 686, in eventfun fun() File "C:\Users\Travi\AppData\Local\Programs\Python\Python36-32\RPG.py", line 20, in up combat() File "C:\Users\Travi\AppData\Local\Programs\Python\Python36-32\RPG.py", line 57, in combat enemy.shape(image) File "C:\Users\Travi\AppData\Local\Programs\Python\Python36-32\lib\turtle.py", line 2777, in shape self.turtle._setshape(name) File "C:\Users\Travi\AppData\Local\Programs\Python\Python36-32\lib\turtle.py", line 2506, in _setshape self._item = screen._createimage(screen._shapes["blank"]._data) File "C:\Users\Travi\AppData\Local\Programs\Python\Python36-32\lib\turtle.py", line 723, in _createimage return self.cv.create_image(0, 0, image=image) File "", line 1, in create_image File "C:\Users\Travi\AppData\Local\Programs\Python\Python36-32\lib\tkinter__init__.py", line 2483, in create_image return self._create('image', args, kw) File "C:\Users\Travi\AppData\Local\Programs\Python\Python36-32\lib\tkinter__init__.py", line 2474, in _create *(args + self._options(cnf, kw)))) _tkinter.TclError: image "pyimage1" doesn't exist
時,我有文件名清楚準確地指出它是我的電腦。
代碼
import os
from turtle import Turtle,Screen
print(os.getcwd())
os.chdir('C:\\Users\\Travi\\Downloads')
screen.register_shape("Crawfish_attack.gif")
turtle = Turtle()
turtle.setimage("Crawfish_attack.gif")
提前感謝 BTW鏈接是here 和代碼的其餘所有作品,並不需要顯示
它是否在您的下載文件夾中名爲Crawfish_attack?否則,您需要從os.chdir()參數的末尾刪除Crawfish_attack –
另外,您是否在更改目錄後嘗試通過打印os.getcwd()來進行調試? –
它在下載中,並且是 – Travis