'Python error - Traceback (most recent call last)
I entered this code. I entered the example alike in the book where I could study Python.
from turtle import Screen, Turtle
import random
screen=Screen()
image1="C:\\rabbit.gif"
image2="C:\\turtle.gif"
screen.addshape(image1)
screen.addshape(image2)
t1=turtle.Turtle()
t1.shape(image1)
t1.pensize(5)
t1.penup()
t1.goto(-300, 0)
t2=turtle.Turtle()
t2.shape(image2)
t2.pensize(5)
t2.penup()
t2.goto(-300, -200)
t1.pendown()
t2.pendown()
t1.speed(1)
t2.speed(1)
for i in range(100):
d1=random.randint(1, 60)
t1.forward(d1)
d2=random.randint(1, 60)
t2.forward(d2)
I entered the code correctly, but there was an error.
Here is the code of the error.
Traceback (most recent call last):
File "D:/대학/파이썬프로그래밍기초/파이썬_과제(2018)/fd.py", line 7, in <module>
screen.addshape(image1)
File "C:\Users\USER\AppData\Local\Programs\Python\Python310\lib\turtle.py", line 1134, in register_shape
shape = Shape("image", self._image(name))
File "C:\Users\USER\AppData\Local\Programs\Python\Python310\lib\turtle.py", line 478, in _image
return TK.PhotoImage(file=filename, master=self.cv)
File "C:\Users\USER\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 4093, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
File "C:\Users\USER\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 4038, in __init__
self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't recognize data in image file "C:\rabbit.gif"
I tried to find a way to correct the error, but I couldn't find it. I wonder where this code is wrong.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
