tkinter的PhotoImage无法识别gif格式图片
from tkinter import *root = Tk()
textLabel = Label(root,text="这是一位美女:")
textLabel.pack(side=LEFT)
photo = PhotoImage(file="1.gif")
imgLabel = Label(root,image=photo)
imgLabel.pack(side=RIGHT)
mainloop()
我的图片原来是jpg格式,我把后缀改成了gif,如图。但是运行出错,无法识别gif格式图片。求助!
Traceback (most recent call last):
File "C:\Users\dwc\Desktop\test\tkinter\tk2.py", line 8, in <module>
photo = PhotoImage(file="1.gif")
File "E:\python36\lib\tkinter\__init__.py", line 3539, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
File "E:\python36\lib\tkinter\__init__.py", line 3495, in __init__
self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't recognize data in image file "1.gif"
谁告诉过你将后缀名改了就是了?
去百度一下gif和jpg之类的文件区别 BngThea 发表于 2017-12-12 17:07
谁告诉过你将后缀名改了就是了?
去百度一下gif和jpg之类的文件区别
这样啊,一直以为改后缀名就可以了。。。谢谢!
我编辑后另存为gif格式的,运行成功了。
页:
[1]