I created a GUI using Tkinter. It has three buttons. one to capture image. second for capturing continuous images until i press third button i.e stop button.
When I press the first button it works fine i.e it runs a function which captures an image and save that image to a particular location.
But when I press the second button for continuous capturing of images then it starts capturing images but button gets stuck or GUI stopped working. because of this I am not able to stop this continuous capturing of images because I cannot press the third button i.e stop button.
I am running a while loop for continuous capturing of images and I can only break this loop if a Global variable STOP will have "0" in it and I can only make it zero by pressing stop button of GUI. But I cannot press stop button to make this STOP variable "0" so that loop can break. I think while loop is stopping the GUI main-loop and creating this problem. if you some have alternative or solution please share it.this is the code
Second button just call this function
def capture_video():
stop = '1'
l=Lepton()
l.enter()
path="/home/ubuntu/Desktop/IR_videos/vid_"
file=open("/home/ubuntu/Desktop/IR_videos/vid_no.txt",'r')
no=file.read()
file.close()
folder_name=path+no
os.mkdir(folder_name)
i=0
print("Image capturing started")
print("____Press Stop button to stop____")
while True:
a=l.capture()
cv2.normalize(a,a,0,65535,cv2.NORM_MINMAX)
np.right_shift(a,8,a)
img=np.uint8(a)
img_name=folder_name+"/"+str(i)+".jpg"
cv2.imwrite(img_name,img)
i=i+1
if stop == "0":
print("Image capturing stoped\n")
print("Press video button to capture again")
break
no=int(no)+1
file=open("/home/ubuntu/Desktop/IR_videos/vid_no.txt",'w')
file.write(str(no))
file.close()
cv2.destroyAllWindows()
l.exit()
here lepton is a class and capture() is function to capture image from flir lepton camera
and this is code of GUI stop button function :
def stop_it():
lep.stop='0'
time.sleep(1)
lep.stop='1'