Let’s learn how we can Generate QR Code with Python, first of all let’s talk about QR Code, and after that we are going to use qrcode Python library for this.
What is QR Code ?
QR code (Quick Response code) is two dimensional barcode that can be scanned using smartphone camera to quickly access information or website. QR codes are used for different purposes, such as storing contact information, URLs, product information and many more. QR codes can store much more information than traditional barcodes, QR codes are good, because they can be scanned using a smartphone or QR code reader. QR codes are often used in advertising, marketing and as a quick and easy way to access information.
How to Generate QR Code with Python ?
First of all we need to instal qrcode library, and you can use pip for the installation, open your command prompt or terminal and write this command.
1 |
pip install qrcode |
This is basic example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
import qrcode # create QR code qr = qrcode.QRCode( version=1, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=10, border=4, ) # add data to be encoded in QR code data = "https://codeloop.org" qr.add_data(data) qr.make(fit=True) # generate image from QR code img = qr.make_image(fill_color="black", back_color="white") # save image to file img.save("qrcode.png") |
This code creates QR code that encodes the URL https://codeloop.org and saves it in to a file at name of qrcode.png. you can customize QR code by adjusting the parameters of QRCodeobject, such as the version (size), error_correction level, box_size and border. make_image function allows you to set the fill color and background color of the QR code.
This will be the result
Subscribe and Get Free Video Courses & Articles in your Email