代码如下,运行之后第一次可以显示图片,关闭之后再打开就显示不了了,但从打印信息来看是可以运行显示的线程的
import cv2
import numpy as np
import threading
from easygui import *
img1 = cv2.imread('01.png')
img2 = cv2.imread('02.png')
img_show=[True]
def img1_method():
print('打开img1')
while img_show[0]:
cv2.imshow("img1",img1)
cv2.waitKey(5)
print('关闭img1')
def img2_method():
print('打开img2')
while img_show[0]:
cv2.imshow("img2",img2)
cv2.waitKey(5)
print('关闭img2')
def open_close():
while True:
choices = ['[1]打开', '[2]关闭', '[3]退出']
choice=buttonbox(msg='请选择', title='cv2测试', choices=choices,
default_choice=choices[2], cancel_choice=choices[2], callback=None, run=True)
choose=choices.index(choice)+1
if choose==1:
img_show[0]=True
threading.Thread(target=img1_method).start()
threading.Thread(target=img2_method).start()
elif choose==2:
img_show[0]=False
else:
break
threading.Thread(target=img1_method).start()
threading.Thread(target=img2_method).start()
threading.Thread(target=open_close).start()