python报错_couldn't recognize data in image file

一、描述

报错:couldn't recognize data in image file

代码:

from tkinter import *

root = Tk()

theLabel = Label(root,text="dog",justify=LEFT,padx=10)
theLabel.pack(side=LEFT)

photo = PhotoImage(file="D:/PythonProject/dog.jpg")
imgLabel = Label(root,image=photo)
imgLabel.pack(side=RIGHT)
root.mainloop()

2.原因

PhotoImage报错,因为file参数只接受gif文件,不能接受jpeg、jpg文件。

gif文件不单指以.gif结尾的文件,而是说图片格式,所以只修改后缀名没有丝毫作用

3.解决

1.上网download一个gif文件。

2.打开,另存成其他格式的文件。

3.使用其他模块。

猜你喜欢

转载自www.cnblogs.com/smxbo/p/13160584.html
今日推荐