Hackernoon logoHow To Generate a QR Code Using Python [5 Lines Code] by@gajesh2007

How To Generate a QR Code Using Python [5 Lines Code]

Author profile picture

@gajesh2007Gajesh Naik

I am Gajesh Naik. I am 12 years old. I started programming at the age of 7. I have skilled 9 P. Lang

Here's the visual edition of this tutorial:
QR code is a type of matrix barcode that is machine readable optical label which contains information about the item to which it is attached. In practice, QR codes often contain data for a locator, identifier, or tracker that points to a website or application, etc.
In this tutorial, you will learn how to generate and read QR codes in Python using qrcode and OpenCV libraries.
Installing required dependencies:
pip3 install pillow qrcode

Generate QR Code

First, let's start by generating QR codes, it is basically straight forward using qrcode library (Full Code):
import qrcode
# example data
data = "https://gajeshsnaik.tech"
# output file name
filename = "site.png"
# generate qr code
img = qrcode.make(data)
# save img to a file
This will generate a new image file in the current directory with the name of "site.png", which contains a QR code image of the data specified (in this case, this website).
Awesome, we are done with this tutorial, you can now integrate this in your own applications! If this tutorial worked for you. Please buy me a coffee of 1$ or more - http://buymeacoff.ee/gajeshnaik
Check out my QR Code Generator Project on https://github.com/Gajesh2007/qrcode_generator_python


The Noonification banner

Subscribe to get your daily round-up of top tech stories!