To generate QR code in Python, you can use the qrcode
package. Install it using pip:
main.py19 chars2 lines
Here's an example code that generates a QR code:
main.py255 chars16 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.
gistlibby LogSnag