qr code generator in python

To generate QR code in Python, you can use the qrcode package. Install it using pip:

main.py
pip install qrcode
19 chars
2 lines

Here's an example code that generates a QR code:

main.py
import qrcode

# data to encode as QR code
data = "https://www.google.com/"

# output file name
filename = "google_qrcode.png"

# generate QR code
img = qrcode.make(data)

# save QR code as PNG file
img.save(filename)

print("QR code saved as", filename)
255 chars
16 lines

In this example, we first import the qrcode package. Then we define the data that we want to encode as QR code, which in this example is a URL to Google.

We also specify the output file name to save the QR code as a PNG file. Then we use qrcode.make() to generate the QR code image. Finally, we save the image using the img.save() method.

The resulting QR code will be saved as google_qrcode.png file in the current directory.

You can replace the data variable with any text or URL that you want to encode as QR code, and change the filename variable to save the QR code with a different name.

Note that this code uses the default QR code size and error correction level. You can customize these options by passing arguments to qrcode.make() method.

related categories

gistlibby LogSnag