QR Code Generator in Python

QR Code Generator in Python

In this post, we will see how to create a QR code generator in Python.

For creating the QR code generator we will be using pyqrcode module of python. This module needs to be installed explicitly on your system because this module does not come up with python already.
For installation:

pip install pyqrcode

Run the above-given command in your command line for installing the given python module.

Steps to follow:

  • First, importing the pyqrcode module.
  • Taking string as input for which QR code needs to create.
  • Create QR object using pyqrcode.create().
  • Save QR object in different formats like SVG or png using respective methods.

Let’s see the Implementation:

# Importing given module to this program
import pyqrcode
  
# String which QR code need to create
input_string = "https://www.biochemithon.in/"
  
# Generating QR code object
# using create() class of
# pyqrcode module
qr_code = pyqrcode.create(input_string) 
  
# Save this qr_code object as a svg file  
# at given location with scale 4 
# using svg() method of qr_code object.
# Scale attribute determine the dimension
# of svg image created.
qr_code.svg(r"C:\Users\hp\OneDrive\Desktop\mywebsite.svg",
            scale = 4)

# Save this qr_code object as a png file  
# at given location with scale 4 
# using png() method of qr_code object.

# For using this png method,
# you must install pypng module first
qr_code.png(r"C:\Users\hp\OneDrive\Desktop\mywebsite.png",
            scale = 4)

Output:

 svg image: 

qrCode image

 png image: 

qrCode png image

Checkout next post on this : QR Code Generator GUI In Python

Note: you must install pypng module before using png() method of qr_code object.

For installation:

pip install pypng

Run the above-given command in your command line for installing the given python module.

Thanks for reading this blog.

If you find this post useful please share it in your groups because Sharing is Caring.

If you have any doubts in understanding the above Code then please comment below, we will try to clear your doubts.

Leave a Reply

Your email address will not be published.

📢 Need further clarification or have any questions? Let's connect!

Connect 1:1 With Me: Schedule Call


If you have any doubts or would like to discuss anything related to this blog, feel free to reach out to me. I'm here to help! You can schedule a call by clicking on the above given link.
I'm looking forward to hearing from you and assisting you with any inquiries you may have. Your understanding and engagement are important to me!

This will close in 20 seconds