"""
Python Application - QR Code Generator App """ import tkinter as tk from tkinter import messagebox import qrcode from PIL import ImageTk def generate_qr(): text = entry.get() if not text: messagebox.showerror("Generate Error", "Please Enter Valid Text/ URL and click generate") return qr = qrcode.QRCode(version=2) qr.add_data(text) qr.make(fit=True) global img, imgtk img = qr.make_image() imgtk = ImageTk.PhotoImage(img) display_qr.config(image=imgtk) display_qr.image = imgtk headline.config(text="Image Generated Successfully") def download_qr(): global img if not img: messagebox.showwarning("Download Warning", "Please click generate first and then click download") return try: img.save("qrcode.jpg", "JPEG") messagebox.showinfo("Download Success", "File has been saved as qrcode.jpg") except Exception as e: messagebox.showerror("Download Error", "An error occured while downloading qrcode") root = tk.Tk() root.title("QR Code Generator") root.geometry("400x500") headline = tk.Label(root, text="Enter Text and Click Generate Button", font=("Arial, 12")) headline.pack(pady=12) entry = tk.Entry(root, width=40, font=("Arial, 12")) entry.pack(pady=12) frame = tk.Frame(root) frame.pack(pady=12) generate_button = tk.Button(frame, text="Generate", font=("Arial, 12"), command=generate_qr) generate_button.pack(side=tk.LEFT, padx=10) download_button = tk.Button(frame, text="Download", font=("Arial, 12"), command=download_qr) download_button.pack(side=tk.LEFT, padx=10) display_qr = tk.Label(root) display_qr.pack(padx=10) img = None imgtk = None root.mainloop()
0 Comments