I need one help in my code what should i do to close test 1 when i click on test 2 to start it again when click on stop.
i have declared two video in two button in my code in Test 1,Test 2 when i click test1 it plays it when i click on 2nd it do same but.. the thing is is when i play test 1 and click on test 2 after that it plays both one and top on other. and when i click stop and click again on test 1 it dont start.
import cv2
from tkinter import *
from PIL import Image, ImageTk
import threading
from tkinter.filedialog import askopenfilename
def resize(image):
im = image
new_siz = siz
im.thumbnail(new_siz, Image.ANTIALIAS)
return im
def size(event):
global siz
if siz == screenWH:
siz = (600, 200)
else:
siz = screenWH
win.state('zoomed')
print ("size is:"), siz
def view_frame_video():
vc = cv2.VideoCapture('C:\\Users\\Devendra\\Desktop\\VID_20190125_172553.mp4')
if vc.isOpened():
rval , frame = vc.read()
else:
rval = False
while rval:
rval, frame = vc.read()
img =Image.fromarray(frame)
img = resize(img)
imgtk = ImageTk.PhotoImage(img)
lbl.config(image=imgtk)
lbl.img = imgtk
if stop == True:
vc.release()
break #stop the loop thus stops updating the label and reading imagge frames
cv2.waitKey(1)
vc.release()
def view_frame_video2():
vc = cv2.VideoCapture('C:\\Users\\Devendra\\Desktop\\VID_20190129_162657.mp4')
if vc.isOpened():
rval , frame = vc.read()
else:
rval = False
while rval:
rval, frame = vc.read()
img =Image.fromarray(frame)
img = resize(img)
imgtk = ImageTk.PhotoImage(img)
lbl.config(image=imgtk)
lbl.img = imgtk
if stop == True:
vc.release()
break #stop the loop thus stops updating the label and reading imagge frames
cv2.waitKey(1)
vc.release()
def stop_():
global stop
stop = True
def play():
stop = False
t = threading.Thread(target=view_frame_video)
t.start()
def play2():
stop = False
t = threading.Thread(target=view_frame_video2)
t.start()
win = Tk()
win.title('Data Logger')
win.geometry('1300x650')
stop = None
screenWH = (win.winfo_screenwidth(), win.winfo_screenheight())
siz = (600, 600)
Label(text='Prosthetic Hand Testing Software',font = ('times',22), fg = 'Red',width = 104, height = 2).pack()
def import_csv_data():
global v
csv_file_path = askopenfilename()
print(csv_file_path)
v.set(csv_file_path)
Label(win, text='File Path',font = ('arial' ,10), fg = 'black', width = 104, height = 2).pack()
v = StringVar()
entry = Entry(textvariable = v)
entry.pack()
Button(text='Browse Data Set',command=import_csv_data).pack()
frm_ = Frame(bg='black')
frm_.pack()
lbl = Label(frm_, bg='black')
lbl.pack(expand=True)
lbl.bind('<Double-Button-1>', size)
buttonframe = Frame(win)
buttonframe.pack(side=BOTTOM)
Button(text='Test 1', command = play,fg="Green", height=2, width=20).pack(side=LEFT)
Button(text='Test 2', command = play2,fg="Green", height=2, width=20).pack(side=LEFT)#,padx=21, pady=18)
Button(buttonframe,text='Stop', command = stop_,fg="Orange", height=2, width=20).pack(side=LEFT,padx=20, pady=18)
Button(buttonframe,text='Exit',fg="Red",command=win.destroy,height=2, width=20).pack(side=LEFT,padx=20, pady=18)
win.mainloop()
should close test 1 and play test 2 when i click on test 2 after test 1 should restart playing test 1,2 when i stop it and click again on any button