Skip to content

Commit 4de8a7c

Browse files
Merge pull request #1642 from sagnik-p/added-QRCODE-Generator
Added qrcode generator
2 parents 4714165 + 0f58768 commit 4de8a7c

File tree

3 files changed

+103
-0
lines changed

3 files changed

+103
-0
lines changed

QR-Code-Generator/QR-generator.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# THIS IS A PYTHON PROGRAM WITH GUI THAT GENERATES A QR CODE OF THE INPUT
2+
# THE INPUT CAN BE A TEXT OR A LINK
3+
# THE QR CODE CAN BE SCANNED BY ANY SCANNER APP
4+
# AUTHOR : https://github.com/sagnik-p
5+
6+
from tkinter import *
7+
from tkinter import messagebox
8+
import os
9+
import pyqrcode
10+
11+
#create a GUI window with tkinter
12+
window = Tk()
13+
window.title("QR Code Generator APP")
14+
15+
# a function to generate all widgets
16+
def generate():
17+
if len(Subject.get()) != 0:
18+
global qr, photo
19+
qr = pyqrcode.create(Subject.get())
20+
photo = BitmapImage(data=qr.xbm(scale=8))
21+
else:
22+
messagebox.showerror("Error","Enter subject first")
23+
try:
24+
showcode()
25+
except:
26+
pass
27+
28+
# a function to show the qr code on the screen
29+
def showcode():
30+
imageLabel.config(image=photo)
31+
subLabel.config(text="QR of " + Subject.get())
32+
33+
# A function to save the qr code as a png file
34+
def save():
35+
dir = os.getcwd() + "\\QR Codes"
36+
if not os.path.exists(dir):
37+
os.makedirs(dir)
38+
try:
39+
if len(name.get()) != 0:
40+
qr.png(os.path.join(dir, name.get() + ".png"), scale=8)
41+
else:
42+
messagebox.showerror("Error","Enter file name first")
43+
except:
44+
messagebox.showerror("Error","Generate the QR code first")
45+
46+
# specifying all details for the widgets
47+
Sub = Label(window, text="Enter URL/Subject")
48+
Sub.grid(row=0, column=0, sticky=N + S + W + E)
49+
50+
FName = Label(window, text="Enter filename to save as")
51+
FName.grid(row=1, column=0, sticky=N + S + W + E)
52+
53+
Subject = StringVar()
54+
SubEntry = Entry(window, textvariable=Subject)
55+
SubEntry.grid(row=0, column=1, sticky=N + S + W + E)
56+
57+
name = StringVar()
58+
nameEntry = Entry(window, textvariable=name)
59+
nameEntry.grid(row=1, column=1, sticky=N + S + W + E)
60+
61+
button = Button(window, text="Generate QR Code", width=15, command=generate)
62+
button.grid(row=0, column=3, sticky=N + S + W + E)
63+
64+
imageLabel = Label(window)
65+
imageLabel.grid(row=2, column=1, sticky=N + S + W + E)
66+
67+
subLabel = Label(window, text="")
68+
subLabel.grid(row=3, column=1, sticky=N + S + W + E)
69+
70+
saveB = Button(window, text="Save as PNG File", width=15, command=save)
71+
saveB.grid(row=1, column=3, sticky=N + S + W + E)
72+
73+
Rows = 3
74+
Columns = 3
75+
76+
for row in range(Rows + 1):
77+
window.grid_rowconfigure(row, weight=1)
78+
79+
for col in range(Columns + 1):
80+
window.grid_columnconfigure(col, weight=1)
81+
82+
# let the program run forever untill manually closed by the user
83+
window.mainloop()

QR-Code-Generator/readme.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Package/Script Name
2+
3+
Generates the qr code of a text or an url
4+
5+
the user also has the option to save the qr code with a custom name, in a png file
6+
7+
## Setup instructions
8+
9+
install the requirements
10+
run the script
11+
12+
## Detailed explanation of script, if needed
13+
14+
COMMENTS used to explain in the script file
15+
16+
## Author(s)
17+
18+
sagnik-p
19+

QR-Code-Generator/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pyqrcode==1.2.1

0 commit comments

Comments
 (0)