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.
Used from Error Level Correction
Used for setting up Size and Data Capacity of the code.
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 = "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)
You can check the QR code by scanning it with any QR code scanner you want.