'How to add one button that enter new video then again enter new video... in python?

I'm pretty new to python and espcially tkinter and opencv.

I want to add new new video in python opencv. how to do this?

This code is mainly for recording purposes.

I want to do like a video player, that add new video

import cv2
import threading
import Tkinter as tk
from PIL import Image, ImageTk   
def stop_rec():
    global running
    running = False
    start_button.config(state="normal")
    stop_button.config(state="disabled")
def start_capture():
    global capture, last_frame
    capture = cv2.VideoCapture("")
    while running:
        rect, frame = capture.read()
        if rect:
            cv2image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGBA)
            last_frame = Image.fromarray(cv2image)
            #video_writer.write(frame)

    capture.release()
def update_frame():
    if last_frame is not None:
        tk_img = ImageTk.PhotoImage(master=video_label, image=last_frame)
        video_label.config(image=tk_img)
        video_label.tk_img = tk_img
    if running:
        root.after(10, update_frame)
def start_rec():
    global running
    running = True
    thread = threading.Thread(target=start_capture, daemon=True)
    thread.start()
    update_frame()
    start_button.config(state="disabled")
    stop_button.config(state="normal")
def closeWindow():
    stop_rec()
    root.destroy()
running = False
after_id = None
last_frame = None
root = tk.Tk()
root.protocol("WM_DELETE_WINDOW", closeWindow)
video_label = tk.Label()
video_label.pack(expand=True, fill="both")
start_button = tk.Button(text="Start", command=start_rec)
start_button.pack()
stop_button = tk.Button(text="Stop", command=stop_rec, state="disabled")
stop_button.pack()
root.mainloop()


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source