Skip to main content
Python

πŸ”₯ Insane QR Code Generator with GUI & Logo (Python Magic!)

Want to create your own QR code generator in Python? Whether you want to encode a website, contact info, or Wi-Fi details, you're in the right place. With just a few lines of code, you'll have a fu…

G

gs_admin

Author & Reviewer

Published

Mar 31, 2025

Read Time

1 min read

article.txt
πŸ“°
Python

Want to create your own QR code generator in Python? Whether you want to encode a website, contact info, or Wi-Fi details, you're in the right place. With just a few lines of code, you'll have a fully working QR code generator β€” and it'll only take you 5 minutes or less. Let's go! πŸ’»πŸ“±

QR Code Generator in Python
QR Code Generator in Python

🧰 What You'll Need

  • Python 3.x installed
  • A terminal or code editor (like VS Code)
  • The qrcode and pillow libraries

Install them by running:

bash
1
pip install qrcode[pil]

That's it. You're ready to go!

🧠 How It Works

We'll use the qrcode library to generate a QR code from any text or URL and save it as an image file.

πŸ“ Step-by-Step Code

python
1234567891011121314151617181920
import qrcode

# Step 1: Enter the data you want to encode
data = input("Enter the text or URL to encode in QR code: ")

# Step 2: Generate QR code
qr = qrcode.QRCode(
    version=1,
    error_correction=qrcode.constants.ERROR_CORRECT_H,
    box_size=10,
    border=4,
)
qr.add_data(data)
qr.make(fit=True)

# Step 3: Create and save the QR image
img = qr.make_image(fill_color="black", back_color="white")
img.save("my_qr_code.png")

print("βœ… QR Code generated and saved as 'my_qr_code.png'")

πŸ§ͺ Example Output

Just run the script, type in a URL like https://example.com, and boom β€” it saves a QR code image you can scan instantly.

🎁 Bonus: Build a GUI QR Code Generator with Color & Logo Support

Want to take this project up a notch? Let's turn it into a user-friendly desktop app with a GUI, complete with color pickers and logo embedding β€” perfect for branding or just flexing your Python skills!

You'll also use tkinter, which comes pre-installed with Python.

python
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
import qrcode
from PIL import Image, ImageTk
import tkinter as tk
from tkinter import filedialog, colorchooser, messagebox

def generate_qr():
    data = entry.get()
    if not data:
        messagebox.showwarning("Input required", "Please enter text or URL!")
        return

    qr = qrcode.QRCode(
        version=1,
        error_correction=qrcode.constants.ERROR_CORRECT_H,
        box_size=10,
        border=4,
    )
    qr.add_data(data)
    qr.make(fit=True)

    qr_img = qr.make_image(fill_color=fill_color.get(), back_color=back_color.get()).convert("RGB")

    # Add logo if selected
    if logo_path.get():
        try:
            logo = Image.open(logo_path.get())
            qr_w, qr_h = qr_img.size

            # Resize logo
            logo_size = int(qr_w / 4)
            logo = logo.resize((logo_size, logo_size))
            pos = ((qr_w - logo_size) // 2, (qr_h - logo_size) // 2)

            qr_img.paste(logo, pos, mask=logo if logo.mode == 'RGBA' else None)
        except Exception as e:
            messagebox.showerror("Logo Error", f"Failed to add logo: {e}")

    filename = filedialog.asksaveasfilename(defaultextension=".png", filetypes=[("PNG files", "*.png")])
    if filename:
        qr_img.save(filename)
        messagebox.showinfo("Success", f"QR Code saved as {filename}")

def choose_color(var):
    color_code = colorchooser.askcolor(title="Choose color")[1]
    if color_code:
        var.set(color_code)

def choose_logo():
    path = filedialog.askopenfilename(filetypes=[("Image files", "*.png;*.jpg;*.jpeg")])
    if path:
        logo_path.set(path)

# GUI
root = tk.Tk()
root.title("QR Code Generator")

tk.Label(root, text="Enter text or URL:").pack(pady=5)
entry = tk.Entry(root, width=40)
entry.pack(pady=5)

fill_color = tk.StringVar(value="black")
back_color = tk.StringVar(value="white")
logo_path = tk.StringVar(value="")

tk.Button(root, text="Pick Fill Color", command=lambda: choose_color(fill_color)).pack(pady=2)
tk.Button(root, text="Pick Background Color", command=lambda: choose_color(back_color)).pack(pady=2)
tk.Button(root, text="Choose Logo (optional)", command=choose_logo).pack(pady=2)

tk.Button(root, text="Generate QR Code", command=generate_qr, bg="green", fg="white").pack(pady=10)

root.mainloop()

πŸ–ΌοΈ What You Get

  • βœ… A fully functioning desktop app
  • 🎨 Custom color support
  • πŸ“· Optional logo embed
  • πŸ“ Save to PNG

🏁 Final Thoughts

You've just created not one but two QR code generators β€” a quick script and a powerful GUI-based app. Whether you're a beginner or looking to enhance your Python project portfolio, this is a fun and practical build to have under your belt.

G

About the Author: gs_admin

A senior technical contributor specializing in architectural designs, software optimization, database structures, and developer education. Passionate about writing clean code and sharing engineering knowledge.