如何解决TclError:无法识别图像文件“black.gif”中的数据我不明白为什么即使文件类型是 GIF 也会出现错误
import turtle
def choos():
listo=['brown.gif','black.gif','green.gif','pink.gif']
n=turtle.Screen()
n.bgcolor("white")
for i in listo:
n.addshape(i)
turtle.shape(i)
turtle.stamp()
turtle.penup()
turtle.fd(100)
turtle.pendown()
first=turtle.textinput("title","choose color for Screen:\n")
if first not in listo:
#
turtle.write("no")
turtle.hideturtle()
choos()
错误:
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-36-0610edf520c4> in <module>
18
19
---> 20 choos()
<ipython-input-36-0610edf520c4> in choos()
4 n.bgcolor("white")
5 for i in listo:
----> 6 n.addshape(f"{i}")
7
8 turtle.shape(i)
C:\ProgramData\Anaconda3\lib\turtle.py in register_shape(self,name,shape)
1131 # image
1132 if name.lower().endswith(".gif"):
-> 1133 shape = Shape("image",self._image(name))
1134 else:
1135 raise TurtleGraphicsError("Bad arguments for register_shape.\n"
C:\ProgramData\Anaconda3\lib\turtle.py in _image(filename)
477 imagedata from a gif-file named filename.
478 """
--> 479 return TK.PhotoImage(file=filename)
480
481 def __init__(self,cv):
C:\ProgramData\Anaconda3\lib\tkinter\__init__.py in __init__(self,cnf,master,**kw)
4059 Valid resource names: data,format,file,gamma,height,palette,4060 width."""
-> 4061 Image.__init__(self,'photo',**kw)
4062
4063 def blank(self):
C:\ProgramData\Anaconda3\lib\tkinter\__init__.py in __init__(self,imgtype,**kw)
4004 v = self._register(v)
4005 options = options + ('-'+k,v)
-> 4006 self.tk.call(('image','create',) + options)
4007 self.name = name
4008
TclError: Couldn't recognize data in image file "black.gif"
我在代码中尝试显示不同颜色的用户图像,他必须选择其中之一,以便所选图像成为屏幕图像,我几乎在互联网上到处寻找错误,但他们总是说将其转换为 GIF 文件,即使它已被转换 我在这里添加了应该显示给用户的图片
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。