0
votes

I am trying to set my image to a file, but when i run it i get

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

when I have the file name clearly stated exactly where it is on my pc.

the code

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")

thanks in advance BTW the link is here and the rest of the code all works and is not needed to be shown

1
Is it in a folder called Crawfish_attack in your downloads? Otherwise you need to remove the Crawfish_attack from the end of your os.chdir() argument - Easton Bornemeier
Also, have you tried debugging by printing os.getcwd() after you changed the directory? - Easton Bornemeier
It is in the downloads, and yes - Travis
The picture is in your downloads, or in a "Crawfish_attack" folder in you downloads? - Easton Bornemeier
Plus I get the error at he Os.chdir command. - Travis

1 Answers

0
votes

Remove "\\Crawfish_attack" from the os.chdir() arguments. You need to path to the folder it is in, not the file. That is what the register_shape function will do is pull the exact file in that folder.

You were getting the error because you were trying to path to something (it was looking for a folder) that does not exist.

import os
from turtle import Turtle,Screen
print(os.getcwd())
os.chdir('C:\\Users\\Travi\\Downloads')
screen.register_shape("Crawfish_attack.gif")