-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqrmaker.py
59 lines (50 loc) · 1.53 KB
/
qrmaker.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
import qrcode
import sys
if sys.version_info[0] == 2:
import Tkinter as tk
else:
import tkinter as tk
class QR_Maker():
# INPUTS AND CUSTOMISATION
def __init__(self, string, size=1, pattern=10, bd=4,
error=qrcode.constants.ERROR_CORRECT_H):
self.URL_to_compile = str(string)
self.sizeOfQR = size
self.sizeOfPattern = pattern
self.border = bd
self.errorCorrecction = error
return
# GENERATING
def compileToQR(self):
qr = qrcode.QRCode(version=self.sizeOfQR,
error_correction=self.errorCorrecction,
box_size=self.sizeOfPattern, border=self.border)
qr.add_data(self.URL_to_compile)
qr.make(fit=True)
return qr.make_image()
# SAVING
def saveQR(self):
outFile = open("QR_OUT.png", "wb")
out = self.compileToQR()
out.save(outFile)
return
# DISPLAYING THE QR CODE
def showCode(self):
wn = tk.Tk()
wn.configure(background='white')
wn.attributes("-fullscreen", True)
QR_img = tk.PhotoImage(file="QR_OUT.png")
cv = tk.Canvas(wn, width=750, height=750)
cv.configure(bg="white", bd=1)
cv.pack()
cv.create_image(0, 0, image=QR_img, anchor=tk.NW)
wn.mainloop()
return
def run(self):
self.saveQR()
self.showCode()
return
pass
if __name__ == '__main__':
QR = QR_Maker("Hallo, ich heisse Yorick.", size=12, pattern=8)
QR.run()