一、描述

报错: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.使用其他模块。

python报错_couldn't recognize data in image file

 

相关文章:

  • 2022-12-23
  • 2022-03-01
  • 2022-12-23
  • 2022-01-25
  • 2021-09-22
  • 2021-07-04
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-08-09
  • 2021-09-15
  • 2021-06-30
  • 2021-08-16
  • 2021-06-05
  • 2021-12-15
  • 2022-12-23
相关资源
相似解决方案