Skip to content

Commit

Permalink
Merge pull request #193 from SpreadSheets600/main
Browse files Browse the repository at this point in the history
Added GUI Version Of QR Code Generator #164
  • Loading branch information
UTSAVS26 authored Oct 7, 2024
2 parents f771eda + 1f3aa0e commit f9ec92c
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions Beginner_Projects/QR Generator/QR_code_generator_GUI.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import qrcode
import customtkinter
from PIL import Image
from customtkinter import *

app = customtkinter.CTk()
app.title("QR Code Generator")
app.geometry("350x600")

img = None
link = None
qr_image = None
image_label = None

def generate_qr():

global link, qr_image, image_label, img

link = link_entry.get()
name = name_entry.get()

qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_M,
)
qr.add_data(link)
qr.make(fit=True)
img = qr.make_image(fill_color="black", back_color="white")
img.save(f"{name}.png")

my_image = customtkinter.CTkImage(light_image=Image.open(f"{name}.png"),
dark_image=Image.open(f"{name}.png"),
size=(200, 200))


image_label = customtkinter.CTkLabel(app, image=my_image, text="")
image_label.grid(row=5, column=0)

def download_qr():
global link, qr_image, image_label

file = f"{name_entry.get()}.png"
img.save(file)


label = customtkinter.CTkLabel(app, text="QR Code Generator", font=("Consolas", 30), compound="center")
label.grid(row=0, column=0, padx=20, pady=20)

link_entry = customtkinter.CTkEntry(app, width=300)
link_entry.grid(row=1, column=0, padx=20, pady=20)

link_entry.configure(placeholder_text="Link")

name_entry = customtkinter.CTkEntry(app, width=300)
name_entry.grid(row=2, column=0, padx=20, pady=20)

name_entry.configure(placeholder_text="Name OF QR Code")

button = customtkinter.CTkButton(app, text="Generate QR Code", command=generate_qr, width=300)
button.grid(row=3, column=0, padx=20, pady=20)

button_download = CTkButton(app, text="Download", command=download_qr, width=300)
button_download.grid(row=4, column=0, padx=20, pady=20)

image_label = None

def change_theme():
if customtkinter.get_appearance_mode() == "Light":
customtkinter.set_appearance_mode("dark")
else:
customtkinter.set_appearance_mode("light")

# Theme Change Btton
theme_button = customtkinter.CTkButton(app, text="Theme", command=change_theme, width=300)
theme_button.grid(row=7, column=0)

app.mainloop()

0 comments on commit f9ec92c

Please sign in to comment.