Libraries Used:
- tkinter (
tk
):- Used for creating the graphical user interface (GUI).
- ttk:
- A themed Tkinter module used for styling buttons in the GUI.
- PIL (Pillow):
- Used for handling images, converting frames from OpenCV to Tkinter-compatible format.
- cv2 (OpenCV):
- Used for video capture, image processing, and barcode detection.
- pyzbar:
- A Python library for reading barcodes using the OpenCV library.
- threading:
- Utilized for running barcode scanning in a separate thread to avoid blocking the main thread and allow for a responsive GUI.
- time:
- Used for introducing a delay to avoid multiple entries for a single barcode scan.
- pygame:
- Utilized for playing a sound when a barcode is detected.
- os:
- Used to obtain the absolute path for the sound file.
- datetime:
- Used for timestamping the saved barcode data.
Application Features:
- GUI Initialization:
- The application initializes a Tkinter window with a specified size and title.
- Styling Configuration:
- The ttk module is used to configure styles for buttons and labels, enhancing the appearance of the UI.
- Video Feed Display:
- The application creates a Tkinter Label to display the video stream captured from the webcam.
- Barcode Scanning Thread:
- The barcode scanning is performed in a separate thread (
barcode_scanner
method) to ensure a responsive GUI.
- The barcode scanning is performed in a separate thread (
- Stop Scanning Button:
- A “Stop Scanning” button is created using ttk.Button. Clicking this button stops the barcode scanning and closes the application window.
- Barcode Scanning Process:
- The application captures the webcam feed and detects barcodes using OpenCV and PyZbar.
- Detected barcodes are displayed on the video feed and added to a set (
scanned_barcodes
) to avoid duplicate entries. - When a new barcode is detected, a sound is played using pygame.
- Display Update:
- The video feed is continuously displayed in the Tkinter window using PIL to convert OpenCV frames to Tkinter-compatible format.
- Data Saving:
- Scanned barcode data, along with timestamps, is saved to a text file (
scanned_data.txt
).
- Scanned barcode data, along with timestamps, is saved to a text file (
- Application Exit:
- The application window is closed gracefully upon stopping barcode scanning.
Usage:
- Run the script, and the Tkinter window will open with the webcam feed.
- The application scans for barcodes continuously.
- Click the “Stop Scanning” button to halt barcode scanning and close the application.
- Scanned barcode data is saved to a text file with timestamps.
Notes:
- Ensure that the required libraries are installed (
tkinter
,opencv-python
,pillow
,pyzbar
,pygame
). - A sound file (
beep.wav
) is expected to be in the same directory as the script. - The application will create or append to the file
scanned_data.txt
in the script’s directory.
7 reviews for Real Time Barcode Scanner With Python & Tkinter
There are no reviews yet.