-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathqr.py
62 lines (48 loc) · 1.44 KB
/
qr.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
from tkinter import *
import pyqrcode
import png
from tkinter import filedialog
from PIL import Image, ImageTk
root = Tk()
root.title("QR Code Generator")
root.iconbitmap('c:/tkinter.com/codemy.ico')
root.geometry('500x550')
def create_code():
#File Dialog
input_path = filedialog.asksaveasfilename(title="Save Image",
filetyp=(("PNG File", ".png"), ("All Files", "*.*")))
if input_path:
if input_path.endswith(".png"):
# Create QR Code from entry box
get_code = pyqrcode.create(my_entry.get())
# Save as PNG File
get_code.png(input_path, scale=5)
else:
# Add that .png to the end of the file name
input_path = f'{input_path}.png'
# Create QR Code from entry box
get_code = pyqrcode.create(my_entry.get())
# Save as PNG File
get_code.png(input_path, scale=5)
# Put QR code on screen
global get_image
get_image = ImageTk.PhotoImage(Image.open(input_path))
# Add image to label
my_label.config(image=get_image)
# Delete entry box
my_entry.delete(0, END)
# Flash up a finished message
my_entry.insert(0, "Finished!")
def clear_all():
my_entry.delete(0, END)
my_label.config(image='')
# Create GUI
my_entry = Entry(root, font=("Helvetica", 18))
my_entry.pack(pady=20)
my_button = Button(root, text="Create QR Code", command=create_code)
my_button.pack(pady=20)
my_button2 = Button(root, text="Clear", command=clear_all)
my_button2.pack()
my_label = Label(root, text='')
my_label.pack(pady=20)
root.mainloop()