How to Create Custom QR Codes in Python (Complete 2025 Guide)

Python | QR code generator

About Project :

In this article, we will explore how to generate a QR code using Python.

A QR code (Quick Response code) is a type of matrix barcode that was invented in 1994 by the Japanese automotive company Denso Wave. Essentially, a barcode is a machine-readable optical label that can contain information about the item to which it is attached.

To achieve this in Python, we can use packages like qrcode and pyqrcode, which allow us to both generate and read QR codes. In this project specifically, we will focus on how to generate QR codes using Python.

To begin with, we will take input from the user, including the URL and basic parameters such as the file name, box size, and more. Based on this input, a QR code will be generated using the provided information.

Finally, you can generate the QR code and save it in PNG format for later use or sharing.

Project Prerequisites:

Before getting started, you need to install two essential Python packages: qrcode and Image.

  • qrcode: This package is used to generate QR codes based on user-defined inputs such as data, box size, and border.

  • Image: This package allows you to save the generated QR code in your desired image format, such as PNG.

Together, these packages enable both the creation and storage of custom QR codes using Python.

Getting Started:

Let’s Get Started

Hello, world! In this section, I will walk you through the process of creating a QR code using Python.

To begin with, let’s take a look at how to generate a QR code in Python.

First, we need to install two essential modules using the command line:

  • qrcode – Install using:

    pip install qrcode

    This module automates most of the process involved in building QR codes and adheres closely to the QR code standard

  • image – Install using:

    pip install image

    This module is used to save the generated QR code in the desired image format

Once these are installed, you’re ready to move on to generating your first custom QR code in Python.

>pip install image
>pip install qrcode

Now, let’s move on to the coding part

Once the required libraries are installed, it’s time to dive into the coding.

We begin by initializing the QR code object using the following syntax:

python
 
qr = qrcode.QRCode(version, box_size, border)

In most cases, creating a QR code only requires the content to be encoded. All other parameters—such as size, box size, and border—will be intelligently inferred based on the content provided. This function returns a QRCode object that you can further customize.

Let’s break down the parameters:

  • version: Specifies the size and data capacity of the QR code. Higher versions can store more data and produce larger codes.

  • box_size: Defines the number of pixels each “box” of the QR code will occupy. It essentially controls the overall image size.

  • border: Sets the thickness of the white border around the QR code. Typically, a minimum border of 4 is recommended.

With this setup, you’re ready to add data and generate the final QR image.

Program:


#Encoding Data into Quick Response Code (QR Code)
import qrcode
 
# Data to encode
data = input('Enter the Data: ')
 
version=int(input('Enter the version (complexity): '))  #maxvalue  15
box_size=int(input('Enter the Box size: '))  # max value 10
 
# Creating an instance of QRCode class
qr = qrcode.QRCode(version ,box_size,border = 5)
 
# Adding data to the instance 'qr'
qr.add_data(data)
 
qr.make(fit = True)
img = qr.make_image(fill_color = 'black',back_color = 'white')
 
f=input("name it as: ")     #image name
 
img.save(f'{f}.png')
 
print('qr code generated and saved in the gallery')
  

after the execution of the program, the QR code will be generated in the same directory with the user’s given name in .png format.

Example:

qrcode generator using python

You can run the above code like this:

Run The Code

Output:

QR CODE

Congratulations – You’ve Generated a QR Code!

At this point, you’ve successfully created a QR code using Python.

You can now scan the QR code using any QR code scanner app, and it will instantly redirect you to youtube.com — or whichever URL you’ve embedded.

This demonstrates how simple and powerful it is to generate QR codes programmatically with Python!

Post You May Also Like: