【发布时间】:2020-09-27 08:26:38
【问题描述】:
我是 python 新手,对 tkinker 和图像有疑问。
我的错误是:
Traceback (most recent call last):
File "D:/python/First Project/Weather app.py", line 12, in <module>
background_image = tk.PhotoImage(file='landscape.jpg')
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\tkinter\__init__.py", line 3542, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\tkinter\__init__.py", line 3498, in __init__
self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't recognize data in image file "landscape.jpg"
相关代码为:
import tkinter as tk
root = tk.Tk()
background_image = tk.PhotoImage(file='D:\python\First Project\landscape.jpg')
background_label = tk.Label(root, image=background_image)
background_label.place(relwidth=1, relheight=1)
root.mainloop()
文件的结尾没有重命名,最初是 .jpg。 我也尝试用
编辑它background_image = ImageTk.PhotoImage(Image.open('your.png'))
【问题讨论】:
-
这个问题没有研究的迹象。这个网站上有很多问题都带有确切的错误消息(文件名除外)。
标签: python tkinter python-3.6