QR Code Attendance System
Abstract
QR Code Attendance System is a Python project that records attendance using QR codes. It demonstrates QR code generation/scanning, file handling, and GUI development. This project is ideal for learning about automation, data management, and real-world applications.
Prerequisites
- Python 3.6 or above
- qrcode (
pip install qrcode
pip install qrcode
) - opencv-python (
pip install opencv-python
pip install opencv-python
) - tkinter (usually pre-installed)
Before you Start
Install Python, qrcode, and OpenCV. Prepare a sample list of users for QR code generation.
Getting Started
- Create a folder named
qr-attendance-system
qr-attendance-system
. - Create a file named
qr_code_attendance_system.py
qr_code_attendance_system.py
. - Copy the code below into your file.
⚙️ QR Code Attendance System
QR Code Attendance System
"""
QR Code Attendance System
A Python application that generates QR codes for users and scans them to mark attendance. Features include:
- Generating QR codes for user identification.
- Scanning QR codes to mark attendance.
"""
import qrcode
import cv2
from tkinter import Tk, Label, Entry, Button, messagebox
from datetime import datetime
class QRCodeAttendanceSystem:
def __init__(self, root):
self.root = root
self.root.title("QR Code Attendance System")
Label(root, text="Enter User ID:").grid(row=0, column=0, padx=10, pady=10)
self.user_id_entry = Entry(root, width=30)
self.user_id_entry.grid(row=0, column=1, padx=10, pady=10)
Button(root, text="Generate QR Code", command=self.generate_qr_code).grid(row=1, column=0, columnspan=2, pady=10)
Button(root, text="Scan QR Code", command=self.scan_qr_code).grid(row=2, column=0, columnspan=2, pady=10)
def generate_qr_code(self):
"""Generate a QR code for the entered user ID."""
user_id = self.user_id_entry.get()
if not user_id:
messagebox.showerror("Error", "Please enter a User ID.")
return
qr = qrcode.QRCode(version=1, box_size=10, border=5)
qr.add_data(user_id)
qr.make(fit=True)
img = qr.make_image(fill="black", back_color="white")
img_path = f"{user_id}_qr.png"
img.save(img_path)
messagebox.showinfo("Success", f"QR Code generated and saved as {img_path}.")
def scan_qr_code(self):
"""Scan a QR code to mark attendance."""
cap = cv2.VideoCapture(0)
detector = cv2.QRCodeDetector()
while True:
ret, frame = cap.read()
if not ret:
break
data, bbox, _ = detector.detectAndDecode(frame)
if data:
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
messagebox.showinfo("Attendance Marked", f"User ID: {data}\nTime: {timestamp}")
break
cv2.imshow("QR Code Scanner", frame)
if cv2.waitKey(1) & 0xFF == ord("q"):
break
cap.release()
cv2.destroyAllWindows()
def main():
root = Tk()
app = QRCodeAttendanceSystem(root)
root.mainloop()
if __name__ == "__main__":
main()
QR Code Attendance System
"""
QR Code Attendance System
A Python application that generates QR codes for users and scans them to mark attendance. Features include:
- Generating QR codes for user identification.
- Scanning QR codes to mark attendance.
"""
import qrcode
import cv2
from tkinter import Tk, Label, Entry, Button, messagebox
from datetime import datetime
class QRCodeAttendanceSystem:
def __init__(self, root):
self.root = root
self.root.title("QR Code Attendance System")
Label(root, text="Enter User ID:").grid(row=0, column=0, padx=10, pady=10)
self.user_id_entry = Entry(root, width=30)
self.user_id_entry.grid(row=0, column=1, padx=10, pady=10)
Button(root, text="Generate QR Code", command=self.generate_qr_code).grid(row=1, column=0, columnspan=2, pady=10)
Button(root, text="Scan QR Code", command=self.scan_qr_code).grid(row=2, column=0, columnspan=2, pady=10)
def generate_qr_code(self):
"""Generate a QR code for the entered user ID."""
user_id = self.user_id_entry.get()
if not user_id:
messagebox.showerror("Error", "Please enter a User ID.")
return
qr = qrcode.QRCode(version=1, box_size=10, border=5)
qr.add_data(user_id)
qr.make(fit=True)
img = qr.make_image(fill="black", back_color="white")
img_path = f"{user_id}_qr.png"
img.save(img_path)
messagebox.showinfo("Success", f"QR Code generated and saved as {img_path}.")
def scan_qr_code(self):
"""Scan a QR code to mark attendance."""
cap = cv2.VideoCapture(0)
detector = cv2.QRCodeDetector()
while True:
ret, frame = cap.read()
if not ret:
break
data, bbox, _ = detector.detectAndDecode(frame)
if data:
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
messagebox.showinfo("Attendance Marked", f"User ID: {data}\nTime: {timestamp}")
break
cv2.imshow("QR Code Scanner", frame)
if cv2.waitKey(1) & 0xFF == ord("q"):
break
cap.release()
cv2.destroyAllWindows()
def main():
root = Tk()
app = QRCodeAttendanceSystem(root)
root.mainloop()
if __name__ == "__main__":
main()
- Run the script:
python qr_code_attendance_system.py
python qr_code_attendance_system.py
Explanation
Code Breakdown
- Import required modules.
import qrcode
import cv2
import tkinter as tk
import qrcode
import cv2
import tkinter as tk
- Generate QR codes.
img = qrcode.make('UserID123')
img.save('user_qr.png')
img = qrcode.make('UserID123')
img.save('user_qr.png')
- Scan QR codes.
cap = cv2.VideoCapture(0)
# ...scan and decode QR codes...
cap = cv2.VideoCapture(0)
# ...scan and decode QR codes...
- GUI for attendance.
root = tk.Tk()
root.title('QR Code Attendance System')
# ...setup widgets for scanning and logging attendance...
root.mainloop()
root = tk.Tk()
root.title('QR Code Attendance System')
# ...setup widgets for scanning and logging attendance...
root.mainloop()
Features
- Generates and scans QR codes
- Records attendance automatically
- GUI for user interaction
- Easy to extend for more features
How It Works
- Generates QR codes for users
- Scans QR codes to record attendance
- Logs attendance in a file or database
GUI Components
- Scan button: Starts QR scanning
- Status display: Shows attendance status
- Log file: Records attendance
Use Cases
- School or office attendance
- Event check-in
- Automate record keeping
Next Steps
You can enhance this project by:
- Adding user authentication
- Exporting attendance logs
- Improving GUI design
- Integrating with cloud storage
Enhanced Version Ideas
def export_logs():
# Save attendance logs to CSV
pass
def add_cloud_sync():
# Sync logs to cloud
pass
def export_logs():
# Save attendance logs to CSV
pass
def add_cloud_sync():
# Sync logs to cloud
pass
Troubleshooting Tips
- QR code not recognized: Check camera and lighting
- Log file errors: Check file permissions
- GUI not showing: Ensure Tkinter is installed
Conclusion
This project teaches QR code handling, automation, and GUI basics. Extend it for more features and better user experience.
Was this page helpful?
Let us know how we did