|
| 1 | +from tkinter import * |
| 2 | +# import os |
| 3 | +import qrcode |
| 4 | +from PIL import Image, ImageTk |
| 5 | +from resizeimage import resizeimage |
| 6 | + |
| 7 | +# QR Code Generator | Designed by Jay Gohel |
| 8 | + |
| 9 | +class Qr_Genrator(): |
| 10 | + def __init__(self, root): |
| 11 | + self.root=root |
| 12 | + self.root.title("QR Code Generator") |
| 13 | + self.root.geometry('900x500+200+50') |
| 14 | + self.root.resizable(False, False) |
| 15 | + |
| 16 | + title = Label(self.root,text=" QR Code Genrator", font=("time new roman",40), bg="#F96900", fg="white", anchor="w").place(x=0,y=0,relwidth=1) |
| 17 | + |
| 18 | + # Variable |
| 19 | + self.var_emp_code=StringVar() |
| 20 | + self.var_name=StringVar() |
| 21 | + self.var_department=StringVar() |
| 22 | + self.var_designation=StringVar() |
| 23 | + |
| 24 | + |
| 25 | + # Employee detail window design |
| 26 | + emp_Frame=Frame(self.root,bd=2, relief=RIDGE,bg="white") |
| 27 | + emp_Frame.place(x=50, y=100, width=500, height=380) |
| 28 | + |
| 29 | + emp_title = Label(emp_Frame,text=" Employee Details", font=("goudy old style",20), bg="#FB9316", fg="white").place(x=0,y=0,relwidth=1) |
| 30 | + lbl_emp_code = Label(emp_Frame,text=" Employee ID", font=("time new roman",15), bg="white").place(x=20,y=60) |
| 31 | + lbl_emp_name = Label(emp_Frame,text=" Name", font=("time new roman",15), bg="white").place(x=20,y=100) |
| 32 | + lbl_emp_dept = Label(emp_Frame,text=" Department", font=("time new roman",15), bg="white").place(x=20,y=140) |
| 33 | + lbl_emp_designation = Label(emp_Frame,text=" Designation", font=("time new roman",15), bg="white").place(x=20,y=180) |
| 34 | + |
| 35 | + |
| 36 | + text_emp_code = Entry(emp_Frame, font=("time new roman",15), textvariable=self.var_emp_code, bg="lightyellow").place(x=200,y=60) |
| 37 | + text_emp_name = Entry(emp_Frame, font=("time new roman",15), textvariable=self.var_name, bg="lightyellow").place(x=200,y=100) |
| 38 | + text_emp_dept = Entry(emp_Frame, font=("time new roman",15), textvariable=self.var_department, bg="lightyellow").place(x=200,y=140) |
| 39 | + text_emp_designation = Entry(emp_Frame, font=("time new roman",15), textvariable=self.var_designation, bg="lightyellow").place(x=200,y=180) |
| 40 | + |
| 41 | + btn_genrator = Button(emp_Frame, text="QR Genrator", command=self.genrate, font=("time new roman", 15, "bold"), bg="#2196f3", fg="white").place(x=90, y=250, width=180, height="30") |
| 42 | + btn_clear = Button(emp_Frame, text="Clear", command=self.clear, font=("time new roman", 15, "bold"), bg="#2196f3", fg="white").place(x=290, y=250, width=120, height="30") |
| 43 | + |
| 44 | + self.msg="" |
| 45 | + self.lbl_msg = Label(emp_Frame, text=self.msg, font=("time new roman",15), bg="white", fg="green") |
| 46 | + self.lbl_msg.place(x=0,y=320, relwidth=1) |
| 47 | + |
| 48 | + |
| 49 | + # Qr Code window design |
| 50 | + qr_Frame=Frame(self.root,bd=2, relief=RIDGE,bg="white") |
| 51 | + qr_Frame.place(x=600, y=100, width=250, height=380) |
| 52 | + |
| 53 | + emp_title = Label(qr_Frame,text="Employee QR code", font=("goudy old style",15), bg="#FB9316", fg="white").place(x=0,y=0,relwidth=1) |
| 54 | + |
| 55 | + self.qr_code = Label(qr_Frame, text="No QR\n available", font=("time new roman",15), bg="#D76C02", fg="white", bd=1, relief=RIDGE) |
| 56 | + self.qr_code.place(x=35, y=100, width=180, height=180) |
| 57 | + |
| 58 | + def clear(self): |
| 59 | + self.var_emp_code.set('') |
| 60 | + self.var_name.set('') |
| 61 | + self.var_department.set('') |
| 62 | + self.var_designation.set('') |
| 63 | + self.msg="" |
| 64 | + self.lbl_msg.config(text=self.msg) |
| 65 | + self.qr_code.config(image='') |
| 66 | + |
| 67 | + |
| 68 | + def genrate(self): |
| 69 | + if self.var_emp_code.get() == '' or self.var_name.get() == '' or self.var_department.get() == '' or self.var_designation.get() == '': |
| 70 | + self.msg="All filed required !!!" |
| 71 | + self.lbl_msg.config(text=self.msg, fg="red") |
| 72 | + |
| 73 | + else: |
| 74 | + qr_data=(f"Employee Id:{self.var_emp_code.get()}\nEmployee Name:{self.var_name.get()}\nDepartment:{self.var_department.get()}\nDesignation:{self.var_designation.get()}") |
| 75 | + qr_code=qrcode.make(qr_data) |
| 76 | + # print(qr_code) |
| 77 | + qr_code=resizeimage.resize_cover(qr_code,[180,180]) |
| 78 | + qr_code.save('./QR-code-Genrator/employee_qr/emp_'+str(self.var_emp_code.get()+'.png')) |
| 79 | + # qr code img update |
| 80 | + self.im=ImageTk.PhotoImage(file='../QR-code-Genrator/employee_qr/emp_'+str(self.var_emp_code.get()+'.png')) |
| 81 | + self.qr_code.config(image=self.im) |
| 82 | + |
| 83 | + # updating noti |
| 84 | + self.msg="QR genrated Successful!!" |
| 85 | + self.lbl_msg.config(text=self.msg, fg="green") |
| 86 | + |
| 87 | +root = Tk() |
| 88 | +obj = Qr_Genrator(root) |
| 89 | +root.mainloop() |
0 commit comments