DEV Community

Cover image for ๐Ÿงพ Build a Custom QR Code Generator Using Python and Streamlit in Minutes!
Nishkarsh Pandey
Nishkarsh Pandey

Posted on

๐Ÿงพ Build a Custom QR Code Generator Using Python and Streamlit in Minutes!

QR codes are everywhere โ€” from restaurant menus to event passes. But what if you could make your own QR code generator with full control over colors and content?

In this quick tutorial, Iโ€™ll show you how to build a fully functional QR Code Generator app using Python and Streamlit. It's beginner-friendly and runs in your browser!

๐Ÿš€ What Weโ€™ll Build
A web app that lets you:
๐Ÿ”ค Enter any text or URL.
๐ŸŽจ Choose custom colors for the QR code and background.
๐Ÿ“ฅ Download the generated QR code image.

Hereโ€™s a sneak peek of what it will look like:
๐Ÿง  Technologies Used
Python.
qrcode โ€“ for generating QR codes.
Pillow (PIL) โ€“ for image manipulation.
Streamlit โ€“ for turning Python into a web app.

๐Ÿงฉ Step 1: Install the Dependencies
First, install the required Python packages:

pip install streamlit qrcode pillow
Enter fullscreen mode Exit fullscreen mode

๐Ÿงพ Step 2: The Code
Create a file called qr_generator.py and paste the following code:

import streamlit as st
import qrcode
from PIL import Image
from io import BytesIO

st.title("๐Ÿงพ QR Code Generator")
data = st.text_input("Enter text or URL:")
fill_color = st.color_picker("Pick QR color", "#000000")
bg_color = st.color_picker("Pick background color", "#ffffff")
if st.button("Generate QR Code") and data:
    qr = qrcode.QRCode(box_size=10, border=4)
    qr.add_data(data)
    qr.make(fit=True)
    img = qr.make_image(fill_color=fill_color, back_color=bg_color).convert("RGB")
    st.image(img)
    buffer = BytesIO()
    img.save(buffer, format="PNG")
    buffer.seek(0)
    st.download_button(
        label="Download QR Code",
        data=buffer,
        file_name="qr_code.png",
        mime="image/png"
    )

Enter fullscreen mode Exit fullscreen mode

๐Ÿงช Step 3: Run the App
Just run this command in the terminal:

streamlit run qr_generator.py
Enter fullscreen mode Exit fullscreen mode

Then open the browser, and youโ€™ll see your own live QR generator ๐ŸŽ‰.

Screenshots:

QRcode

๐Ÿ”ฎ Bonus Ideas
Add a logo to the center of the QR.
Save a history of generated codes.
Turn it into a Chrome extension.
Deploy it with Streamlit Community Cloud.

๐Ÿซถ Final Thoughts
With just a few lines of Python, youโ€™ve built a cool and useful tool. You can now generate customized QR codes anytime โ€” perfect for business cards, events, links, and more.

If you liked this, give it a โค๏ธ and follow me for more beginner-friendly Python + Streamlit projects.
Have questions or want to collab? Drop a comment below ๐Ÿ‘‡

Top comments (0)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.