SoFunction
Updated on 2024-10-30

Python using QRCode module to generate QR code example details

Python generates QR codes using the QRCode module

QRCode official website

/pypi/qrcode/5.1

synopsis

python-qrcode is a third-party module for generating QR code images that relies on the PIL module and the qrcode library.

simple usage

import qrcode 
img = ('hello, qrcode')
('')
 

Advanced Usage

import qrcode 
qr = (   
  version=1,   
  error_correction=.ERROR_CORRECT_L,   
  box_size=10,   
  border=4, 
) 
qr.add_data('hello, qrcode') 
(fit=True) 
img = qr.make_image()
('')

Parameter Meaning:

version: the value is an integer from 1 to 40, which controls the size of the QR code (the minimum value is 1, which is a 12×12 matrix). If you want the program to determine it automatically, set the value to None and use the fit parameter.

error_correction: controls the error correction function of the QR code. Can take values of the following 4 constants.
ERROR_CORRECT_L: About 7% or less of errors can be corrected.
ERROR_CORRECT_M (default): about 15% or less of errors can be corrected.
ROR_CORRECT_H: About 30% or less of the errors can be corrected.

box_size: controls the number of pixels contained in each small cell in the QR code.

border: controls the number of squares contained in the border (the distance between the QR code and the image boundary) (default is 4, which is the minimum value specified by the relevant standard)

Thanks for reading, I hope this helps, and thanks for supporting this site!