In this tutorial, we will create a Python GUI desktop application using Tkinter that displays a live webcam feed and allows users to capture images using OpenCV and Pillow.
Prerequisites
Make sure you have Python 3 installed along with the required dependencies:
Full Code for Webcam GUI App
Explanation
- We use
cv2.VideoCapture(0)
to access the webcam. - The
update_frame
function continuously updates the Tkinter label with the live feed. - The
capture_image
function captures an image when the button is clicked and saves it ascaptured_image.jpg
. - The
on_closing
function ensures proper cleanup when the window is closed.
Running the Application
Save the script as webcam_app.py
and run it using: