0

我正在尝试在此代码中显示图像“picture.gif”:

from graphics import *
import tkinter

win = GraphWin("Self Portrait", "1000", "500")
image = Image(Point(5,5), "picture.gif")
image.draw(win)
window.mainloop()

但是,我不断收到此错误:

Traceback (most recent call last):
  File "/Users/jstorrke/Desktop/Python/graphicsProject.py", line 6, in <module>
    image = Image(Point(5,5), "picture.gif")
  File "/Users/jstorrke/Desktop/Python/graphics.py", line 827, in __init__
    self.img = tk.PhotoImage(file=pixmap[0], master=_root)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/tkinter/__init__.py", line 3394, in __init__
    Image.__init__(self, 'photo', name, cnf, master, **kw)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/tkinter/__init__.py", line 3350, in __init__
    self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't recognize data in image file "picture.gif"
4

2 回答 2

0

_tkinter.TclError:无法识别图像文件“picture.gif”中的数据

我查看了数十个示例此错误消息,原因似乎分为两类:

1) 文件不是受支持的类型(例如 *.jpg、*.png、*.tif),这从扩展名中很明显。

2) 使用的文件被错误标记为 *.gif 而不是。(比我想象的更常见。)在 Unix 系统上,您可以使用该file命令来验证您的 GIF:

> file p7Q6O.gif 
p7Q6O.gif: GIF image data, version 89a, 520 x 416
> 

如果它是不受支持的动画 GIF,则会发生有效 GIF 文件的实际故障。但是,这可能是无声的失败——没有错误消息,也没有显示图像。

于 2017-05-20T19:07:12.590 回答
0

图形模块为显示图像提供了非常少的支持。尝试将图像放在与图形库所在的文件夹相同的文件夹中,看看是否有帮助。

请查看此文档以获取有关图形模块的更多信息。http://mcsp.wartburg.edu/zelle/python/graphics/graphics.pdf

于 2017-05-17T21:49:56.920 回答