To generate a QR code in Python, you can use the qrcode
library. Here is an example of how to generate a QR code containing a simple message:
import qrcode
# create the QR code object
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
)
# add the message to the QR code object
qr.add_data('https://medium.com/@adilaziz2013')
# make the QR code image
qr.make(fit=True)
# create an image from the QR code object
img = qr.make_image(fill_color="black", back_color="white")
# save the QR code image to a file
img.save('qr_code.png')
This will generate a QR code image containing the message and save it to a file called qr_code.png
.
You can customize the appearance and behavior of the QR code by modifying the parameters passed to the QRCode
object. For example, you can change the version of the QR code (which determines its size and capacity), the error correction level (which determines how much data can be recovered if the QR code is damaged), the box size (which determines the size of the individual blocks in the QR code), and the border size (which determines the width of the border around the QR code).
You can also add other data to the QR code, such as URLs, text, or binary data. The qrcode
library supports a wide range of data types and provides various options for customizing the appearance and behavior of the QR code.