QR Code Generator with Python

QR Codes are super helpful for redirecting users to different internet pages with only your mobile phone camera. They are super beneficial but have you ever thought about creating them? There's actually a Python module for this exact purpose. 

The PyQRCode module takes a link and a few other attributes to return a working QR code in just a few lines of simple code. We will also use the pypng module and the pillow module for saving the file as a png and showing it, respectively. 

Once you get the modules installed on your device, we can get straight into the code:

#Importing necessary modules

import pyqrcode

from PIL import Image

#Getting a link

link = "https://thepygrammer.blogspot.com/"

#Creating the QR code

qr_code = pyqrcode.create(link)

#Saving the QR code as a .png file

qr_code.png("QR.png",scale=5)

#Using Image to show the generated QR Code

qr_png = Image.open("QR.png")

qr_png.show()

Once you execute this code, the QR code gets generated. We can use the Image.open() and Image.show() functions to show the code on our screen. Here's the output for this code...


So, here we have a working QR code generator for all your quick QR generations, and we managed to do it within 10 lines of code. Cool, right ?

If you found this post helpful, do check out my other posts. The comment section is open for all queries and comments, so feel free to use it. Until next time...

If you want to check out some other posts:












Comments