-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui.py
More file actions
173 lines (149 loc) · 3.85 KB
/
gui.py
File metadata and controls
173 lines (149 loc) · 3.85 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
from pathlib import Path
from tkinter import *
from tkinter import Tk, Canvas, Entry, Text, Button, PhotoImage, messagebox,filedialog
import tkinter as tk
import pyqrcode
import png
OUTPUT_PATH = Path(__file__).parent
ASSETS_PATH = OUTPUT_PATH / Path(r"C:\Users\Tushar\Desktop\Qr code generator\assets\frame0")
def relative_to_assets(path: str) -> Path:
return ASSETS_PATH / Path(path)
def generate_Qr():
print("button_1 clicked")
if len(user_input.get()) !=0:
global qr,img
qr=pyqrcode.create(user_input.get())
img = BitmapImage(data=qr.xbm(scale=5))
else:
messagebox.showwarning('warning',"fields are required!")
try:
create_download_button()
display_code()
except:
pass
def display_code():
image_1_lbl.config(image= img)
print("QR code generated : "+ user_input.get())
def create_download_button():
download_button = Button(
image=download_buttonimg,
borderwidth=0,
highlightthickness=0,
relief="flat",
text="Download QR Code",
command=download_qr_code
)
download_button.place(
x=237.0,
y=465.0,
width=163.0,
height=51.0
)
def download_qr_code():
save_path = tk.filedialog.asksaveasfilename(defaultextension=".png", filetypes=[("PNG files", "*.png")])
if save_path:
qr.png(save_path, scale=10)
messagebox.showinfo("Download Successful", f"QR Code saved to {save_path}")
else:
messagebox.showwarning("Warning", "Failed!")
def on_entry_click(event):
if entry_1.get() == "Enter Text":
entry_1.delete(0, tk.END)
entry_1.configure(foreground="black")
def on_focus_out(event):
if entry_1.get() == "":
entry_1.insert(0, "Enter Text")
entry_1.configure(foreground="gray")
window = Tk()
window.title("QR Code Generator")
window.geometry("990x600")
window.configure(bg = "#FFFFFF")
canvas = Canvas(
window,
bg = "#FFFFFF",
height = 600,
width = 990,
bd = 0,
highlightthickness = 0,
relief = "ridge"
)
canvas.place(x = 0, y = 0)
canvas.create_text(
60.0,
20.0,
anchor="nw",
text="Qr generator",
fill="#000000",
font=("Bold", 50 * -1)
)
canvas.create_text(
52.0,
194.0,
anchor="nw",
text="Create Your QR Code\nin Just a Few Clicks",
fill="#000000",
font=("Inter SemiBold", 40 * -1)
)
canvas.create_text(
52.0,
313.0,
anchor="nw",
text="Paste a url or enter text to create a QR code",
fill="#000000",
font=("Inter Light", 18 * -1)
)
entry_image_1 = PhotoImage(file=relative_to_assets("entry_1.png"))
entry_bg_1 = canvas.create_image(
272.0,
404.5,
image=entry_image_1
)
user_input = StringVar()
entry_1 = Entry(
bd=0,
bg="#FFFFFF",
fg="#000716",
textvariable = user_input,
highlightthickness=0,
font=("Inter Light", 15* -1)
)
entry_1.place(
x=69.0,
y=373.0,
width=406.0,
height=61.0
)
entry_1.insert(0, "Enter Text")
entry_1.bind("<FocusIn>", on_entry_click)
entry_1.bind("<FocusOut>", on_focus_out)
image_image_1 = PhotoImage(file=relative_to_assets("image_1.png"))
image_1 = canvas.create_image(
751.0,
337.0,
image=image_image_1
)
image_1_lbl =Label(
window,
bg='#E0E0E0')
image_1_lbl.place(
x=620.0,
y=195.0,
width=263.0,
height=285.0
)
generate_buttonimg = PhotoImage(file=relative_to_assets("button_1.png"))
download_buttonimg = PhotoImage(file=relative_to_assets("button_2.png"))
button_1 = Button(
image=generate_buttonimg,
borderwidth=0,
highlightthickness=0,
relief="flat",
command = generate_Qr
)
button_1.place(
x=49.0,
y=465.0,
width=163.0,
height=51.0
)
window.mainloop()