Python Tkinter QR Code Generator
Welcome to QR Code Generator
This is QR Code Generator using python.
You can need to 2 modules qrcode , tkinker
#
# copyright by pyprojectlab
#
import qrcode
from tkinter import *
from tkinter import filedialog
import os
def get_code():
data_var = data.get()
save_as = name_to_save.get()
if not data_var or not save_as:
label.config(text="Please fill in both fields", bg="yellow")
return
qr = qrcode.make(str(data_var))
base.loc = filedialog.askdirectory()
print("Selected Directory:", base.loc) # Debug print
if base.loc:
save_path = os.path.join(base.loc, f"{save_as}.png")
print("Save Path:", save_path) # Debug print
try:
qr.save(save_path)
label.config(text="Done", bg="green")
except Exception as e:
label.config(text=f"Error: {e}", bg="red")
else:
label.config(text="No directory selected", bg="red")
# Get a Tk window of 400 * 200
base = Tk()
base.geometry("400x200")
base.title("QR Code Generator")
data = StringVar()
name_to_save = StringVar()
label_1 = Label(base, text="QR Name").place(x=80, y=10)
dataEntry = Entry(base, textvariable=name_to_save, width="30")
dataEntry.place(x=80, y=30)
label_2 = Label(base, text="INSIDE QRCODE").place(x=80, y=50)
dataEntry2 = Entry(base, textvariable=data, width="30")
dataEntry2.place(x=80, y=70)
button = Button(base, text="Get Code", command=get_code, width="30", height="2", bg="grey")
button.place(x=80, y=100)
label = Label(base, text="", bg="white")
label.place(x=80, y=150)
base.mainloop()
Comments