β‘ Python Power Shots β π§Ύ QR Code Generator
Posted on: October 7, 2025
Description:
π Introduction
Want to share a link, contact info, or any piece of text instantly? With Pythonβs qrcode library, you can generate your own scannable QR codes β no internet connection, no external tools.
This Power Shot helps you turn any URL or text into a QR code image in just a few lines of code. You can customize colors, borders, and even the size to match your branding or style.
π Explanation
- qrcode.QRCode() creates a configurable QR generator object.
- Parameters like version, error_correction, box_size, and border let you control the size and robustness of your QR code.
- You can encode any data β URLs, text, contact info, or even small payloads like tokens or keys.
- Once generated, the QR code can be saved as an image and shared directly.
- Works completely offline and is extremely lightweight.
β Key Takeaways
- π§Ύ Convert any text or link into a QR code instantly.
- βοΈ Customize the QR style, color, and border easily.
- πΎ Save and reuse QR codes across your projects or print media.
Code Snippet:
"""
Programmer: python_scripts (Abhijith Warrier)
PYTHON SCRIPT TO GENERATE A QR CODE USING qrcode ππ§Ύπ±
This script turns any text or URL into a scannable QR code image. You can customize
colors, borders, and sizes easily.
Perfect for sharing project links, contact info, or secrets securely.
"""
# Import the qrcode library to generate QR codes
import qrcode
# --- Step 1: Define the text or URL you want to encode ---
# Replace this link or text with your own content
data = ""
# --- Step 2: Create a QRCode object with configuration ---
# version: controls the size (1 = small, 40 = large)
# error_correction: defines how much of the code can be restored if damaged
# box_size: size of each pixel box in the QR grid
# border: thickness (number of boxes) around the code
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
)
# --- Step 3: Add data and build the QR code ---
qr.add_data(data)
qr.make(fit=True)
# --- Step 4: Create an image from the QR code ---
# fill_color sets the QR dots color; back_color sets the background
img = qr.make_image(fill_color="black", back_color="white")
# --- Step 5: Save the QR code image ---
# You can change the filename or format (e.g., .jpg, .bmp)
img.save(".png")
print("β
QR Code generated successfully and saved")
Link copied!
Comments
Add Your Comment
Comment Added!
No comments yet. Be the first to comment!