tkinter列表框不会显示完整的内容,只能运行一次

我正在同时通过3台摄像机的图像(使用multiprocessing来测量物体,现在我被困在GUI中。我创建了一个按钮,按下该按钮可执行图像处理并计算测量值,但是有两个问题:

  1. 该按钮仅工作一次,如果再次按下该按钮,程序将无响应。
  2. 在按钮功能中,创建了一个Listbox以列表形式显示值,但仅显示前2个测量值,而其他未显示。

这是主窗口的代码:

window = tk.Tk()
window.title("CVIM")

Lb1 = tk.Listbox(window)
Lb1.insert(1,"Length=")
Lb1.insert(2,"Width=")
Lb1.insert(3,"front length=")
Lb1.insert(4,"Front width=")
Lb1.insert(5,"back length=")
Lb1.insert(6,"Back width=")

Lb1.pack(side='left')

canvas = tk.Canvas(window,width = int(ch*1.5),height = int(cw/1.5)) # bg='blue'
canvas.pack(side='top')
tk.Label(text="IMAGES").pack(side='top')

tk.Button(window,text="Quit",command=exit).pack(side='bottom')
tk.Button(window,text="snapshot",command=lambda: snapshot(window,canvas)).pack(side='bottom')
CheckVar = tk.IntVar()
tk.Checkbutton(window,text = "Preview",variable = CheckVar,onvalue = 1,offvalue = 0,height=10,width = 0).pack(side='bottom')

window.mainloop()

这是快照按钮的代码:

def snapshot(window,canvas):
    imgs=[];
    for ind,que in enumerate(queues):
        frame = que.get()
        imageRGB=cv2.cvtColor(frame,cv2.COLOR_BGR2RGB)
        imgs.append(imageRGB)

    #Imageprocessing code here
    dims=[tL,tW,fL,fW,bL,bW]

    Lb2 = tk.Listbox(window)

    for ind,measurements in enumerate(dims):
        Lb2.insert(ind,"{:.2f}mm".format(measurements) )
    Lb2.pack(side='left')

这是按钮第一次起作用时得到的image

l239984503 回答:tkinter列表框不会显示完整的内容,只能运行一次

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3120591.html

大家都在问