首页 > 解决方案 > 显示图像 tkinter macOSX

问题描述

我一直在寻找几个小时从一个站点跳到另一个站点,从一个视频到另一个视频搜索可以工作的东西。根本没有对我有用!

from tkinter import *
import tkinter.messagebox

root = Tk()

photo = PhotoImage(file='download.jpg')
label = Label(root, image = photo)
label.pack()

root.mainloop()
Error:
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7 "/Users/Datboi/PycharmProjects/untitled2/Tkinter test.py"
Traceback (most recent call last):
  File "/Users/Datboi/PycharmProjects/untitled2/Tkinter test.py", line 6, in <module>
    photo = PhotoImage(file='download.jpg')
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/tkinter/__init__.py", line 3539, in __init__
    Image.__init__(self, 'photo', name, cnf, master, **kw)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/tkinter/__init__.py", line 3495, in __init__
    self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't recognize data in image file "download.jpg"

Process finished with exit code 1

https://imgur.com/a/0RiX51A

我只是简单地尝试以特定尺寸显示图片,但它无法识别图像文件。我正在寻找替代品。

标签: pythontkinter

解决方案


推荐阅读