-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
75 lines (57 loc) · 2.24 KB
/
app.py
File metadata and controls
75 lines (57 loc) · 2.24 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
import tkinter as tk
import ttkbootstrap as ttk
from PIL import Image, ImageTk
import qrcode
import os
import glob
# Function to create QR code and save in "QrCodes" folder
def generate_qrcode(text):
# Create the "QrCodes" directory if it doesn't exist
os.makedirs("QrCodes", exist_ok=True)
# Save the QR code in the "QrCodes" folder
filename = os.path.join("QrCodes", f"{text.replace(' ', '_')}.png")
img = qrcode.make(text)
filename.replace('/', '')
img.save(filename)
# Load and display the image
image = Image.open(filename)
image = ImageTk.PhotoImage(image)
# Update the label with the new image
image_label.config(image=image)
image_label.image = image # Keep a reference to avoid garbage collection
# Function to delete all PNG files in the "QrCodes" folder
def delete_qrcodes():
files = glob.glob("QrCodes/*.png")
for f in files:
os.remove(f)
print("All QR code images deleted.")
# Initialize the Tkinter app with ttkbootstrap theme
app = ttk.Window(themename="darkly") # Change the theme for a modern look
app.title("QR Code Generator")
app.resizable(False, False)
input_Var = tk.StringVar()
# Create the UI elements with improved styling
txt_Label = ttk.Label(app, text='Welcome to the QRCode Generator!',
font=('Calibri', 22, 'bold'),
bootstyle="primary")
txt_Label.pack(pady=(30, 10))
description = ttk.Label(app, text="Create your custom QR Code with one click!",
font=('Calibri', 14),
bootstyle="light")
description.pack(pady=(0, 20))
txt_entry = ttk.Entry(app, textvariable=input_Var,
font=('Calibri', 15),
width=30,
bootstyle="info")
txt_entry.pack(pady=(0, 20))
gen_Button = ttk.Button(app, text='Generate',
command=lambda: generate_qrcode(input_Var.get()),
bootstyle="success-outline")
gen_Button.pack(pady=10)
del_Button = ttk.Button(app, text='Delete All QR Codes',
command=delete_qrcodes,
bootstyle="danger-outline")
del_Button.pack(pady=10)
image_label = ttk.Label(app)
image_label.pack(pady=(30, 0), padx=10)
app.mainloop()