
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python Generate QR Code using pyqrcode module?
A QR code consists of black squares arranged in a square grid on a white background, which can be read by an imaging device such as a camera. It is widely used for many commercial tracking applications and payment and website login etc. for various applications aimed at mobile-phone users. The pyqrcode module is used to generate the qrcocode in python. There are four standardized encoding modes (numeric, alphanumeric, byte/binary, and kanji) to store data efficiently.
Alphanumeric qrcode
We use the pyqrcode module. It has the cerate function which will be used to generate the qrcode. Finally we save it as a svg file and scale it to proper size as required. We can open the svg file and see it using the browser.
Example
import pyqrcode from pyqrcode import QRCode # String input for the QR code str = "learnPython" # Generate QR code qrcd = pyqrcode.create(str) # Create and save the svg file qrcd.svg("qrcd.svg", scale=10)
Output
Running the above code gives us the following result −
Binary qrcode
We can also have a binary form of the qrcode using a similar code but with additional parameter. We just mark the mode as binary for the cerate function. The code looks slightly different to the human eye because of the level of compression.
Example
import pyqrcode from pyqrcode import QRCode # String input for the QR code str = "learnPython" # Generate QR code qrcd = pyqrcode.create(str, mode='binary') # Create and save the svg file qrcd.svg("qrcd2.svg", scale=10)
Output
Running the above code gives us the following result −
- Related Articles
- Python module to Generate secure random numbers
- Malicious QR Code with QRGen
- Differentiate between Fastag, Bar Code, QR Code and NFC.
- QR code generating website in Django
- How to generate byte code file in python
- How to create QR code in R?
- Histograms Equalization using Python OpenCv Module
- Testing in Python using doctest module
- ASCII art using Python pyfiglet module
- How to code the tkinter "scrolledtext" module?
- What are the differences between Fastag and QR Code?
- What are the differences between Barcode and QR Code?
- What are the differences between QR code and NFC?
- Reading an image using Python OpenCv module
- Prefix matching in Python using pytrie module
