Python Tkinter发出调用另一个脚本的问题
我在学校的一个项目上遇到了一些麻烦。该项目涉及在树莓pi上运行python代码,使用pi摄像头“检测斑块”。它真的只是在图片中拾取黄色 我提前表示歉意,我对编码一无所知,所以我将尽我所能描述这个问题,只提供必要的信息 当我尝试使用tkinter按钮调用一个脚本时,我遇到了一个错误,但是我尝试调用的脚本本身工作得非常好。这就是我得到的错误:Python Tkinter发出调用另一个脚本的问题,python,user-interface,tkinter,Python,User Interface,Tkinter,我在学校的一个项目上遇到了一些麻烦。该项目涉及在树莓pi上运行python代码,使用pi摄像头“检测斑块”。它真的只是在图片中拾取黄色 我提前表示歉意,我对编码一无所知,所以我将尽我所能描述这个问题,只提供必要的信息 当我尝试使用tkinter按钮调用一个脚本时,我遇到了一个错误,但是我尝试调用的脚本本身工作得非常好。这就是我得到的错误: Exception in Tkinter callback Traceback (most recent call last): File "/
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 "/home/pi/Desktop/PC_working_code/Final.py", line 54, in process
import seniordesign_colordetect_trial
File "/home/pi/Desktop/PC_working_code/seniordesign_colordetect_trial.py", line 150, in <module>
label=tki.Label(window,image=finalimg,width=600, height=450)
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
导致错误的高级设计部分如下所示。如果我注释掉标签,那么它工作得很好,但标签实际上是代码中唯一对我需要的东西很重要的部分
window=tki.Tk()
window.title("Results")
window.geometry("650x1050+0-29")
window.configure(background='white')
cv2.imwrite(filename='image.jpg', img=imageFrame)
finimg=Image.open('/home/pi/Desktop/PC_working_code/image.jpg')
resizeimg=finimg.resize((600,450),Image.ANTIALIAS)
finalimg=ImageTk.PhotoImage(resizeimg)
label=tki.Label(window,image=finalimg,width=600, height=450)
label.pack()
def close():
window.destroy()
button1=tki.Button(window, text="Take Another Picture", height=4, width=30, bg="red", fg="white",
relief="solid", font=("arial", 24, "bold"), command=close)
button1.pack()
任何帮助都会很棒。我很迷茫,在谷歌搜索时没有任何运气。你是否创建了多个
Tk
实例?你开始运行时是否存在/home/pi/Desktop/PC\u working\u code/image.jpg
?我看到它被cappic
捕获。您确实有cv2.imwrite(filename='image.jpg'…)
,但您确定运行时您在桌面
文件夹中吗?@BryanOakley对不起,但我不知道这是什么意思。@timrobts它确实存在,但我一直让cappic覆盖图像。我相信我是在桌面
上运行的,因为包括图像在内的所有内容都在PC_working_code
文件夹中,这是显示图像的标签,对其进行注释,图像从未使用过,也没有此类错误。删除所有子项Tk()
,并将其设置为Toplevel()
。只保留一个Tk()
。
window=tki.Tk()
window.title("Results")
window.geometry("650x1050+0-29")
window.configure(background='white')
cv2.imwrite(filename='image.jpg', img=imageFrame)
finimg=Image.open('/home/pi/Desktop/PC_working_code/image.jpg')
resizeimg=finimg.resize((600,450),Image.ANTIALIAS)
finalimg=ImageTk.PhotoImage(resizeimg)
label=tki.Label(window,image=finalimg,width=600, height=450)
label.pack()
def close():
window.destroy()
button1=tki.Button(window, text="Take Another Picture", height=4, width=30, bg="red", fg="white",
relief="solid", font=("arial", 24, "bold"), command=close)
button1.pack()