我正在用python制作一个照相亭。我正在使用 tkinter 来做到这一点:
from tkinter import *
from tkinter import font
import os
from PIL import Image
from PIL import ImageTk
load = Image.open("./image1.jpg")
def startCallBack():
tf = Tk()
render = ImageTk.PhotoImage(load)
img = Label(tf, image=render)
img.image = render
img.pack()
root.destroy()
tf.mainloop()
root = Tk()
appHighlightFont = font.Font(family='Helvetica', size=48, weight='bold')
label=Label(root, text='PHOTO BOOTH', font=appHighlightFont)
btn = Button( root, text ="START", command = startCallBack )
label.place(relx=0.5, rely=0.4,anchor="center")
btn.place(relx=0.5, rely=0.6,anchor="center")
root.mainloop()
但是当我启动这个脚本时,会出现一个错误:
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python3.7/tkinter/__init__.py", line 1705, in __call__
return self.func(*args)
File "photobooth.py", line 10, in startCallBack
img = Label(tf, image=render)
File "/usr/lib/python3.7/tkinter/__init__.py", line 2766, in __init__
Widget.__init__(self, master, 'label', cnf, kw)
File "/usr/lib/python3.7/tkinter/__init__.py", line 2299, in __init__
(widgetName, self._w) + extra + self._options(cnf))
_tkinter.TclError: image "pyimage1" doesn't exist
图像与脚本位于同一目录中,我使用的是 Raspberry Pi 4B 4GB RAM
请帮忙!