Translate

03 December 2022

Generate a QRCode using PYTHON QRCode Module | PYTHON PYQRCODE.

HOW TO GENERATE OR CREATE A QRCODE USING PYTHON  

              =

                                              

What is Qrcode ? 

- Qrcode is nothing but an image containing an some information embedded in it and after scanning it the persons who scans it can get the information embedded in it as in the form of link url or some text .

So this is what the Qrcode is all about.


To create or make a qrcode with the help of python is more easy as because as it a vast an powerful programming language it has some library or packages available to make the work easy and possible with few lines of code.

Requirements :

  • Python latest version
  • Pycharm IDE
  • QRcode library installed
  • Pillow library installed  


The steps to make or create qrcode using python are as follows:


step 1 : Open you pycharm IDE and create one project named the qrcode .

step 2 : Goto the terminal of pycharm IDE or open command prompt and type the below given command. 

  • pip install qrcode
  • pip install pillow

step 3 : After this write the code given below.

#code for qrcode is this and it was written with all details of each line in comment
import qrcode
from PIL import Image
# Press the green button in the gutter to run the script.
boxsize = input("enter the qrsize : ")
qr = qrcode.QRCode(
version=3, # this version indicates the complexity of qr as it increases in number
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=boxsize, # size of the qrcode
border=2, # indicates the border given to qrcode
)
# url input from user
url = input("enter the link that you want to embed in qr : ")
# adding data to the url
qr.add_data(url)
qr.make(fit=True)
# taking the qrcode pattern fill color from user
fcolor = input("enter the fcolor : ")
# making qrcode using make_image method
img = qr.make_image(fill_color=fcolor, back_color="white")
qr.make(fit=True)
# saving image to the the directory by user given name
imgname = input("enter the name to save the image : ")
name = imgname+".png"
img.save(name)
print("qrcode created and saved successfully....")
print("wait now opening the image...")
print("loading...")
# opening the image using the pillow library and the path was the folder name
img1 = Image.open(r"C:\Users\thakk\PycharmProjects\opencvimgprocessing"+"\\"+name)
# img1 = Image.open(r"here give path of your folder where the project is saved"+"\\"+name)
img1.show()

step 4 : Now make some changes to the second last line i.e. add the path of the folder where the project is saved.

then run the code by clicking the run button on top right 


step 5 : Now give the input as needed 


C:\Users\thakk\PycharmProjects\opencvimgprocessing\venv\Scripts\python.exe C:/Users/thakk/PycharmProjects/opencvimgprocessing/main.py

enter the qrsize : 10

enter the link that you want to embed in qr : https://www.youtube.com/@crazytechHT

enter the fcolor : red

enter the name to save the image : qrcode1

qrcode created and saved successfully....

wait now opening the image...

loading...


Process finished with exit code 0


Note : Wait for some time and let the image to opens from folder.  as sometime it take bit time to load and as it totally depends on the processor you are running on .

step 6 : Output as image opens an qrcode generated as :





Thanks for reading

visit Again











No comments:

Post a Comment