programming languageTutorials
Trending

How to generate A QR code using Python

You can generate QR codes in Python by using the qrcode library. Here is a simple example code to generate a QR code image:

import qrcode

# create QR code instance
qr = qrcode.QRCode(version=1, box_size=10, border=4)

# add data to the QR code
data = "https://example.com"
qr.add_data(data)
qr.make(fit=True)

# create an image from the QR code
img = qr.make_image(fill_color="black", back_color="white")

# save the image as a PNG file
img.save("example.png")

In this example, we first import the qrcode library. We then create a QR code instance with the desired size and border using the QRCode class. Next, we add the data to the QR code using the add_data method and make the QR code using the make method. Finally, we create an image from the QR code using the make_image method and save the image as a PNG file using the save method.

You can customize the QR code’s appearance by adjusting the fill_color and back_color parameters of the make_image method.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button