Tkinter-枕头库-打开图像时无法调用TypeError'dict'对象

时间:2020-09-16 10:27:09

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

使用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”对象不可调用

我该如何解决?

1 个答案:

答案 0 :(得分:0)

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