Python tkinker错误:无法´;无法识别图像文件中的数据
我是python新手,对tkinker和图像有问题 我的错误是:Python tkinker错误:无法´;无法识别图像文件中的数据,python,tkinter,python-3.6,Python,Tkinter,Python 3.6,我是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\A
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"
该文件的结尾未重命名,最初为.jpg。
我还试着用
background_image = ImageTk.PhotoImage(Image.open('your.png'))
PhotoImage
方法似乎不支持JPG文件。在使用jpg文件时,我收到了相同的错误(无法识别“image.jpg”
中的数据)。使用PNG文件时,我没有收到任何此类错误
请注意,不能仅更改JPG文件的文件扩展名将其转换为PNG文件,因为PNG文件中的数据不同于JPG文件。您需要将JPG文件转换为PNG(或
PhotoImage
方法支持的任何其他图像文件类型)。此问题没有研究迹象。这个网站上有很多关于这个错误消息的问题(除了文件名)。
background_image = ImageTk.PhotoImage(Image.open('your.png'))