TGViewer
Learn Python Coding Learn Python Coding @pythonre · 40.9K subscribers
Post #8824 1.34K
import qrcode

# Data to be encoded
custom_data = "This is a custom QR code made with Python!"

# Instantiate the QRCode class with custom parameters
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_H, # High error correction
box_size=15,
border=5,
)

# Add the data to the QR code instance
qr.add_data(custom_data)
qr.make(fit=True)

# Create the image with custom colors
# fill_color is the color of the QR code blocks
# back_color is the background color
img_custom = qr.make_image(fill_color="darkblue", back_color="white")

# Save the custom image
img_custom.save("custom_python_qr.png")

print("Customized QR code generated successfully and saved as 'custom_python_qr.png'")


In this example:
• We create a QRCode object with specific settings for version, error_correction, box_size, and border.
• We use qr.add_data() to add our content.
• qr.make(fit=True) finalizes the QR code structure.
• qr.make_image() generates the actual image object, where we can specify the colors.
• Finally, we save the resulting image.

---

Conclusion

You now have the tools to generate QR codes effortlessly using Python. You've learned how to create a quick, standard QR code with qrcode.make() and how to build a fully customized one using the QRCode class to control everything from size and durability to color.

#### What's Next?

• Integrate into Applications: Add QR code generation to a web application (e.g., a Flask or Django app) to create user-specific codes.
• Generate Different Content: Encode Wi-Fi network details, contact information (vCards), or calendar events.
• Dynamic Generation: Build a script that takes user input to generate QR codes on the fly.

━━━━━━━━━━━━━━━
By: @DataScience4 ✨
  • ❤ 6
  • 👍 3
More from @pythonre
  1. Oct 17, 2026😰 15-Hour "Python for Data Science" Course ⚡️ Learn Python for Data Science https://enghu…
  2. Oct 13, 2026https://substack.com/@husseinsheikho?utm_source=share&utm_medium=android&r=3hwnr8 Follow m…
  3. Oct 10, 2026📚 Download 10 Python books for FREE: 1. Think Python — O’Reilly https://t.co/X7y3pX68IW 2…
  4. Oct 7, 2026Python Lists: A Quick Reference 🐍 * Definition: Lists are ordered, mutable collections th…
  5. Oct 7, 2026📱 270 tools for Python developers The repository contains: 🫡 Linters and formatters; 🫡…
  6. Oct 7, 2026Hands On Python Data Science - Data Science Bootcamp Master Python for Data Science with R…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →