python报错_tkinter.TclError: couldn’t recognize data in image file “D:\images\1 (10).jpg”
练习用label部件显示图片和文本的代码:
import tkinter as tk
filename = 'D:\\images\\1 (10).jpg'
root = tk.Tk()
photo = tk.PhotoImage(file=filename)
label1 = tk.Label(root,text='学习python', justify='left',
image=photo,compound='center',font=('Consolas',10),fg='white')
label1.pack()
root.mainloop()
运行报错
_tkinter.TclError: couldn't recognize data in image file "D:\images\1 (10).jpg"
把后缀改成.gif,报错依旧,去找了张真正的gif图(如下)
运行效果:
还是静态的???看来是只改后缀是不行的,要用工具(PS,格式工厂什么的软件)将.jpg或.png图片转化成.gif图片格式才可以
新的问题又产生了:动态图在窗口显示的只是静态的,怎么使之如原来一样动起来呢?
查找到的解决方法:使用tkinter显示动态gif