pythonturtle-graphicsnosuchfileexception

how to add shape in turtle


I am trying to re-create the legend of zelda 1986 version in python and I immediately ran into a problem. I cant add the link gif to be the shape. Here is my code:

from turtle import*
screen=Screen()
link=Turtle()
walk="grid-cell-18443-1434401894-3.gif"
sword="legend-of-zelda-86.gif"
screen.addshape(walk)
screen.addshape(sword)
link.shape("walk")

I got an error. in short,

"_tkinter.TclError: couldn't open "grid-cell-18443-1434401894-3.gif": 
no such file or directory"

It is a real file in the downloads folder! Please help!

And thank you in advance.


Solution

  • It looks like your source code is running from a different location to where your images are stored.

    If you move your images to your source code directory, you should not get the no such file or directory error.

    You can check the current directory of your interpreter using functions from the os module.

    import os
    print(os.getcwd())
    

    You can also change to the appropriate directory if you don't want to move the files.

    os.chdir("/path/to/files")