【问题标题】:Tkinter - Pillow library - TypeError 'dict' object not callable when opening imageTkinter - 枕头库 - 打开图像时 TypeError 'dict' 对象不可调用
【发布时间】:2020-09-16 10:27:09
【问题描述】:

使用 Pillow 库在 Tkinter 中打开 .png 图像时出现错误。

from tkinter import *
from PIL import ImageTk, Image

root = Tk()
root.title("MainWindow")
root.iconbitmap('tkinter_programicon.ico')

my_image = ImageTk.PhotoImage(Image.OPEN("image.png"))
my_label = Label(image=my_image)
my_label.pack()

exit_button = Button(root, text="Exit Program", command=root.quit)
exit_button.pack()

root.mainloop()

错误:
my_image = ImageTk.PhotoImage(Image.OPEN("image.png"))
TypeError: 'dict' 对象不可调用

我该如何解决这个问题?

【问题讨论】:

  • Image.OPEN(...) 应该是 Image.open(...)。

标签: python-3.x tkinter python-imaging-library


【解决方案1】:

您应该将my_image = ImageTk.PhotoImage(Image.OPEN("image.png")) 行更改为my_image = ImageTk.PhotoImage(Image.open("image.png"))。

【讨论】:

    猜你喜欢
    • 2017-05-27
    • 2011-10-01
    • 2020-08-01
    • 2012-10-31
    • 2016-03-07
    • 2019-08-10
    • 2019-02-27
    • 1970-01-01
    相关资源
    最近更新 更多