tkinter发出调用另一个脚本的问题

qmelpv7a  于 2021-07-13  发布在  Java
关注(0)|答案(0)|浏览(223)

我在学校的一个项目上遇到了一些麻烦。该项目包括在树莓pi上运行python代码,使用pi摄像机“检测斑块”。它真的只是在照片上看到了黄色。
我提前道歉我对编码一无所知,所以我将尽我所能描述这个问题,只提供必要的信息。
当我尝试使用tkinter按钮调用一个脚本时,我遇到了一个错误,但是我尝试调用的脚本本身运行得非常好。这就是我得到的错误:

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

我有一个脚本,基本上只是一个图形用户界面和相机预览。这个叫做“final.py”。它正在调用另一个执行所有分析的脚本“seniordesign\u colordetect\u trial.py”。为了简单起见,我称之为高级设计。
final用 cappic . 然后final使用tkintergui按钮调用seniorddesign。以下是期末考试的重要部分。

def cappic():
        camera.capture('/home/pi/Desktop/PC_working_code/image.jpg')
        webcam.release()
        img_new = cv2.imread('image.jpg', cv2.IMREAD_GRAYSCALE)
        cv2.waitKey(1650)
        cv2.destroyAllWindows()
        img_ = cv2.imread('image.jpg', cv2.IMREAD_ANYCOLOR)
        img_resized = cv2.imwrite(filename='saved_img-final.jpg', img=img_)

    button1 = tki.Button(window, text="Capture Teeth", height=4, width=30, bg="red", fg="white", 
    relief="solid", font=("arial", 24, "bold"), command=cappic)
    button1.place(x=40, y=600)

    def process():
        camera.stop_preview()
        import seniordesign_colordetect_trial
        camera.start_preview(fullscreen=False, window = (75,100,500,600))

    button2 = tki.Button(window, text="Process Picture", height=4, width=30, bg="red", fg="white",relief="solid", font=("arial", 24, "bold"),command=process) 
    button2.place(x=40, y=800)

导致错误的设计部分如下所示。如果我注解掉了标签,那么它工作得很好,但是标签实际上是代码中唯一对我需要的东西很重要的部分。

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()

任何帮助都太好了。我很迷路,没有任何运气搜索谷歌。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题