QR Code Generator

QR Code Generator Screenshot

Project Overview

This QR Code Generator is a feature-rich Python application built with Tkinter that creates customizable QR codes for websites, contact information, Wi-Fi credentials, or any text data. Going beyond basic QR code generation, this tool offers personalization options including custom colors, logo integration, different error correction levels, and even custom framing with text.

Interactive Demo

Try the QR Code Generator below. Enter a URL and customize your QR code with different colors and options.

Your QR code will appear here

Features

Custom Colors

Choose any color combination for your QR code and its background.

Logo Integration

Add your logo or any image to the center of the QR code.

Error Correction

Select from four levels of error correction to ensure your QR code remains scannable even if partially damaged.

Custom Framing

Add a frame with custom text around your QR code for better presentation.

Multiple Formats

Export your QR codes in PNG or JPEG format based on your needs.

User-Friendly Interface

Simple and intuitive Tkinter GUI makes QR code generation accessible to everyone.

Application Interface

The application provides a clean user interface with fields for all customization options:

QR Generator Interface

Technical Implementation

The QR Code Generator is built with Python and leverages several key libraries:

Core Components

Code Architecture

The core function responsible for QR code generation:

def create_qr_code(url, filename='qr_code.png', box_size=10, border=4, fill_color='black', back_color='white', version=1, error_correction='L', logo_path=None, output_format='PNG', frame_text=None): try: # Map error correction level error_correction_levels = { 'L': qrcode.constants.ERROR_CORRECT_L, 'M': qrcode.constants.ERROR_CORRECT_M, 'Q': qrcode.constants.ERROR_CORRECT_Q, 'H': qrcode.constants.ERROR_CORRECT_H } # Create a QR code instance qr = qrcode.QRCode( version=version, error_correction=error_correction_levels.get(error_correction, qrcode.constants.ERROR_CORRECT_L), box_size=box_size, border=border, ) # Add data to the QR code qr.add_data(url) qr.make(fit=True) # Create an image from the QR Code instance img = qr.make_image(fill_color=fill_color, back_color=back_color).convert('RGB') # Add logo if provided if logo_path: logo = Image.open(logo_path) logo_size = min(img.size) // 5 logo = logo.resize((logo_size, logo_size), Image.ANTIALIAS) pos = ((img.size[0] - logo_size) // 2, (img.size[1] - logo_size) // 2) img.paste(logo, pos, mask=logo) # Add a frame around the QR code if frame_text: # Create a new image with extra space for the frame frame_width = img.size[0] + 40 frame_height = img.size[1] + 80 framed_img = Image.new('RGB', (frame_width, frame_height), back_color) draw = ImageDraw.Draw(framed_img) # Paste the QR code onto the framed image qr_x = (frame_width - img.size[0]) // 2 qr_y = 40 framed_img.paste(img, (qr_x, qr_y)) # Add text to the frame font = ImageFont.load_default() text_bbox = draw.textbbox((0, 0), frame_text, font=font) text_width = text_bbox[2] - text_bbox[0] text_height = text_bbox[3] - text_bbox[1] text_x = (frame_width - text_width) // 2 text_y = frame_height - text_height - 20 draw.text((text_x, text_y), frame_text, fill=fill_color, font=font) img = framed_img # Save the image in the specified format img.save(filename, format=output_format) print(f"QR code saved as '{filename}' for URL: {url}") except Exception as e: print(f"An error occurred: {e}")

The UI is built with Tkinter to provide a user-friendly interface for all the customization options:

Sample QR Code Output

How to Use

  1. Enter the URL or text you want to encode in the QR code
  2. Customize the appearance:
    • Choose fill and background colors
    • Select error correction level
    • Optionally add a logo
    • Optionally add frame text
  3. Click "Generate QR Code" button
  4. Save the QR code to your desired location in PNG or JPEG format

Applications

The QR Code Generator is versatile and useful in various scenarios:

Back to Projects