Running webcam and tkinter at the same time Running webcam and tkinter at the same time tkinter tkinter

Running webcam and tkinter at the same time


Of course it is possible, as mentioned by @Dunno you need to run them in separate threads. Use threading module.

from tkinter import *import cv2import tkinter as tkimport threadingui = Tk()ui.state('normal')canvas = tk.Canvas()canvas.pack(fill = 'both', expand = True)def video_stream():  video = cv2.VideoCapture(0)  a = 0  while True:    a+= 1    check, frame = video.read()    cv2.imshow('Video', frame)    key = cv2.waitKey(1)    if key == 27:        break  video.release()  cv2.destroyAllWindowsth= threading.Thread(target=video_stream) #initialise the threadth.setDaemon(True)th.start() #start the threadui.mainloop() #Run your UI