QR Code Generator
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:
Technical Implementation
The QR Code Generator is built with Python and leverages several key libraries:
Core Components
- qrcode Library: For generating the QR code structure and data encoding
- PIL (Pillow): For image manipulation, including adding logos and frame text
- Tkinter: For creating the graphical user interface
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:
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
}
qr = qrcode.QRCode(
version=version,
error_correction=error_correction_levels.get(error_correction, qrcode.constants.ERROR_CORRECT_L),
box_size=box_size,
border=border,
)
qr.add_data(url)
qr.make(fit=True)
img = qr.make_image(fill_color=fill_color, back_color=back_color).convert('RGB')
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)
if frame_text:
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)
qr_x = (frame_width - img.size[0]) // 2
qr_y = 40
framed_img.paste(img, (qr_x, qr_y))
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
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:
How to Use
- Enter the URL or text you want to encode in the QR code
- Customize the appearance:
- Choose fill and background colors
- Select error correction level
- Optionally add a logo
- Optionally add frame text
- Click "Generate QR Code" button
- 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:
- Business cards and marketing materials
- Website and social media links
- Event tickets and check-ins
- Wi-Fi network sharing
- Contact information sharing
- Product packaging and labeling
Back to Projects