C:\>pythonPython 3.10.4 (tags/v3.10.4:9d38120, Mar 23 2022, 23:13:41) [MSC v.1929 64 bit (AMD64)] on win32Type "help", "copyright", "credits" or "license" for more information.
# Import required Librariesfromtkinterimport*fromPILimportImage,ImageTkimportcv2# Create an instance of TKinter Window or framewin=Tk()# Set the size of the windowwin.geometry("640x480")# Create a Label to capture the Video frameslabel=Label(win)label.grid(row=0,column=0)cap=cv2.VideoCapture(0)# Define function to show framedefshow_frames():# Get the latest frame and convert into Imagecv2image=cv2.cvtColor(cap.read()[1],cv2.COLOR_BGR2RGB)img=Image.fromarray(cv2image)# Convert image to PhotoImageimgtk=ImageTk.PhotoImage(image=img)label.imgtk=imgtklabel.configure(image=imgtk)# Repeat after an interval to capture continiouslylabel.after(20,show_frames)show_frames()win.mainloop()