-
Notifications
You must be signed in to change notification settings - Fork 13
/
QR_code.py
73 lines (56 loc) · 1.88 KB
/
QR_code.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from tkinter import *
import os
import pyqrcode
window = Tk()
window.title("QR Code Generator")
def generate():
if len(Subject.get())!=0 :
global qr,photo
qr = pyqrcode.create(Subject.get())
photo = BitmapImage(data = qr.xbm(scale=8))
else:
messagebox.showinfo("Please Enter some Subject")
try:
showcode()
except:
pass
def showcode():
imageLabel.config(image = photo)
subLabel.config(text="QR of " + Subject.get())
def save():
dir = os.getcwd() + "\\QR Codes"
if not os.path.exists(dir):
os.makedirs(dir)
try:
if len(name.get())!=0:
qr.png(os.path.join(dir,name.get()+".png"),scale=8)
else:
messagebox.showinfo("Please enter a File Name")
except:
messagebox.showinfo("Generate the QR code first!")
Sub = Label(window,text="Enter subject")
Sub.grid(row =0,column =0,sticky=N+S+W+E)
FName = Label(window,text="Enter FileName")
FName.grid(row =1,column =0,sticky=N+S+W+E)
Subject = StringVar()
SubEntry = Entry(window,textvariable = Subject)
SubEntry.grid(row =0,column =1,sticky=N+S+W+E)
name = StringVar()
nameEntry = Entry(window,textvariable = name)
nameEntry.grid(row =1,column =1,sticky=N+S+W+E)
button = Button(window,text = "Generate",width=15,command = generate)
button.grid(row =0,column =3,sticky=N+S+W+E)
imageLabel = Label(window)
imageLabel.grid(row =2,column =1,sticky=N+S+W+E)
subLabel = Label(window,text="")
subLabel.grid(row =3,column =1,sticky=N+S+W+E)
saveB = Button(window,text="Save as PNG",width=15,command = save)
saveB.grid(row =1,column =3,sticky=N+S+W+E)
#making this resposnsive
Rows = 3
Columns = 3
for row in range(Rows+1):
window.grid_rowconfigure(row,weight=1)
for col in range(Columns+1):
window.grid_columnconfigure(col,weight=1)
window.mainloop()