Build a QR Code Generator Using Python


Create Your Own QR Codes in Seconds – No Design Skills Needed!

QR codes are everywhere — from restaurant menus to product packaging and even payment apps. But did you know you can create your own QR Code Generator using just a few lines of Python code?

In this blog, you'll learn how to build a QR Code Generator in Python using a powerful library called qrcode. It’s beginner-friendly, fast, and super useful for both fun and professional projects.


🧰 What You Need:

  • Python installed (Python 3+)

  • Internet connection

  • Basic knowledge of Python

  • Install one simple package: qrcode


📦 Step 1: Install Required Library

Open your terminal or command prompt and run:

bash
pip install qrcode[pil]

🧠 This installs the qrcode library along with Pillow, which helps create images.


🧱 Step 2: Write the Python Code

Create a file called qr_generator.py and paste this code:

python
import qrcode # Get user input data = input("Enter the text or URL to generate QR Code: ") # Create QR Code qr = qrcode.QRCode( version=1, # size of the QR Code (1 to 40) box_size=10, # size of each box in pixels border=5 # thickness of the border ) qr.add_data(data) qr.make(fit=True) # Create and save the image img = qr.make_image(fill="black", back_color="white") img.save("my_qrcode.png") print("✅ QR Code generated and saved as 'my_qrcode.png'")

🧪 Step 3: Run Your Program

Run your script from the terminal:

bash
python qr_generator.py

💬 Enter any text, URL, or data — for example:

arduino
https://www.expertsnippet.com

📁 The QR code image (my_qrcode.png) will be saved in your project folder.


🖼️ Example Output:

You can scan the generated QR Code with any phone to open the embedded link or text.


🚀 Bonus: Generate Colorful QR Codes

Want to customize your QR code colors? Try this:

python
img = qr.make_image(fill_color="blue", back_color="yellow") img.save("custom_qrcode.png")

🎨 Try different color combinations like red/white, green/black, etc.


🔧 Upgrade Ideas:

  • Create a GUI using Tkinter

  • Generate QR Codes in bulk using a CSV file

  • Build a web version using Flask or Django

  • Auto-email the QR code to users


Conclusion

With just a few lines of Python code, you've created a fully functional QR Code Generator. It’s a great beginner project that introduces you to:

  • External libraries

  • User input

  • Image generation

  • File handling

You can use this app for sharing URLs, business cards, app links, Wi-Fi access, and more!


💬 Want a version with a user interface or web deployment guide? Comment below and I’ll help you build it!

Post a Comment

Post a Comment (0)

Previous Post Next Post