Sec Cam
Sec Cam

Reputation: 67

tkinter GUI app with camera on closed camera is still running

In tkinter window I have camera from OpenCV

cv2.VideoCapture(0)

When I click on Button [X] in the corner app is closed but camera is still runing. Now I have 2 case

-1. case if I put only quit() window is [Not Responding] and OS kill window. When I try next time run application camera is working normally.

self.root = tk.Tk()

self.root.quit()

-2. case if I put quit() and destroy() window is closed perfect. When I try next time run application camera is black because camera is still running.

self.root = tk.Tk()

self.root.quit()
self.root.destroy()

And My final question is I want 1. case but I want window close normally

Upvotes: 0

Views: 821

Answers (1)

PRMoureu
PRMoureu

Reputation: 13317

You should release the capture stream at the end :

self.stream = cv2.VideoCapture(0)
self.root = tk.Tk()

# [...]

self.stream.release()
self.root.quit()

Here you can grab some doc about openCV.

Upvotes: 1

Related Questions