简体   繁体   English

Python:无法在Zelle graphics.py中显示图像,tkinter无法读取图像数据

[英]Python: Can't display images in Zelle graphics.py, tkinter can't read image data

I am trying to display the image "picture.gif" in this code: 我正在尝试通过以下代码显示图像“ 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()

However, I keep getting this error: 但是,我不断收到此错误:

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"

The graphics module provides very minimal support for displaying images. 图形模块为显示图像提供了非常少的支持。 Try putting the image on the same folder as where graphics library is and see if it helps. 尝试将图像放在与图形库所在的文件夹中,看看是否有帮助。

Please look at this document for more information on graphics module. 请查看此文档以获取有关图形模块的更多信息。 http://mcsp.wartburg.edu/zelle/python/graphics/graphics.pdf http://mcsp.wartburg.edu/zelle/python/graphics/graphics.pdf

_tkinter.TclError: couldn't recognize data in image file "picture.gif" _tkinter.TclError:无法识别图像文件“ picture.gif”中的数据

I looked at dozens of examples this error message and the cause seems to fall into two categories: 我查看了数十个错误消息示例,其原因似乎可分为两类:

1) The file wasn't a supported type (eg *.jpg, *.png, *.tif) which was obvious from the extension. 1)文件不是受扩展名支持的类型(例如* .jpg,*。png,*。tif)。

2) The file used was mislabeld as a *.gif when it wasn't. 2)所使用的文件未标记为* .gif。 (More common than I would expect.) On Unix systems you may be able to use the file command to verify your GIF: (比我预期的更常见。)在Unix系统上,您可以使用file命令来验证您的GIF:

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

An actual failure of a valid GIF file occurs if it's an animated GIF which are not supported. 如果有效的GIF文件是不支持的动画GIF,则会发生实际失败。 However, this can be a silent failure -- no error message and no image displayed. 但是,这可能是无提示的故障-没有错误消息,也没有图像显示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM