Generating a QR Code in Python 3.x. or earlier

In this tutorial, we will learn about how to generate QR code in Python 3.x. or earlier using “pyqrcode”¬†module.

Generate QR Code in Python

You can generate QR code in Python in multiple ways. But as this is CodeSpeedy and CodeSpeedy always look for the best and simplest way to achieve a goal. Thus we think pyqrcode module is best for us to generate QR code easily and save that in an image file. Here we will show you how to save the QR code in the svg format in our example.

The pyqrcode module allows us to generate a QR code. The module involves automation of the creation process for generating QR codes. The terminology of Qr Code used in pyqrcode module comes directly from the standard.



Installation of pyqrcode via pip

>>> pip install pyqrcode

Create function – pyqrcode.create()

.create(content, error=’h’, version=None, encoding=None):

For creating a QR code only the content for which encoding is required. The output of the function will return a QR Code object. To be more specific with the properties of required QR Code by the help of arguments inside the create function.

error:

Used from Error Level Correction

version:

 Used for setting up Size and Data Capacity of the code.

mode:

 Style in which contents must be encoded.

Source Code: Python Program to create QR Code

# Importing the module pyqrcode 
import pyqrcode 


# address of the website for which we are making qr code 
s = "www.codespeedy.com"

# Generate QR code by the help of create function 
url = pyqrcode.create(s) 

# saving the svg file naming "myqr.png" 
url.svg("myqr.svg", scale = 8) 

Output:

generate QR code in Python Program

Output: QR Code in Python

You can check the QR code by scanning it with any QR code scanner you want.

Also, learn
String objects with their operations in Python 3
Formatting of Strings in Python New method V/S Old method

Leave a Reply

Your email address will not be published. Required fields are marked *