46 lines
1.4 KiB
Python
46 lines
1.4 KiB
Python
import tkinter as tk
|
|
from tkinter import messagebox
|
|
import qrcode
|
|
import openpyxl
|
|
|
|
def create_qr_codes():
|
|
# Đọc dữ liệu từ tệp Excel
|
|
wb = openpyxl.load_workbook('listUser.xlsx')
|
|
sheet = wb.active
|
|
first_row_skipped = False
|
|
# Duyệt qua từng dòng trong tệp Excel và tạo mã QR code
|
|
for row in sheet.iter_rows(values_only=True):
|
|
name, role = row[0], row[1]
|
|
|
|
# Bỏ qua dòng đầu tiên
|
|
if not first_row_skipped:
|
|
first_row_skipped = True
|
|
continue
|
|
|
|
if name != None and role != None:
|
|
# Tạo nội dung cho mã QR code
|
|
qr_data = f"{name}\n{role}\n\n"
|
|
|
|
# Tạo mã QR code
|
|
qr = qrcode.QRCode(
|
|
version=1,
|
|
error_correction=qrcode.constants.ERROR_CORRECT_L,
|
|
box_size=10,
|
|
border=4,
|
|
)
|
|
qr.add_data(qr_data)
|
|
qr.make(fit=True)
|
|
|
|
# Lấy hình ảnh mã QR code
|
|
img = qr.make_image(fill_color="black", back_color="white")
|
|
|
|
# Lưu hình ảnh mã QR code vào tệp
|
|
img_file_name = f"./QRCode/{name}_{role}_qr_code.png"
|
|
img.save(img_file_name)
|
|
|
|
print(f"QR code created for {name}, {role}")
|
|
|
|
messagebox.showinfo("Success", "QR codes created successfully.")
|
|
|
|
create_qr_codes()
|