how to add shape in turtle

5.6k Views Asked by At

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.

2

There are 2 best solutions below

0
On BEST ANSWER

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

the problem is where you did walk="grid-cell-18443-1434401894-3.gif" and then later using the string walk for turtle/tkinter. what you should do is either move file "grid-cell-18443-1434401894-3.gif" to your python file, or do this code:

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