We can create QR code for any url link using Python. QR creation using python code is very easy to execute and user friendly to edit. Python code is given below for ready use.

Home Page - Basic Engineer
Home Page – Basic Engineer

Solution: How to generate QR Code using python for a URL.

Pre-Requisite:

1.     System should have Python 3.x.x version

2.     Environment variable should set

Optional:

Jupyter Notebook is not mandatory but can help in debugging and showing results on same page

Note: This code is specific for the qr code generation of URL links we generally use in user manuals, devices and documents.

Code Section: (SVG Format)

import pyqrcod
from pyqrcode import QRCode
  
  
# Taking a website for example (You can change as per your need)
se = "www.se.com/"
  
# Create QR code
link = pyqrcode.create(se)
  
# Save qr code in svg file format naming "sepic.svg"
link.svg("sepic.svg", scale = 8)e

Results:

Image file “sepic.svg” generated at base location.

Result – QR Code
import pyqrcode
import png
from pyqrcode import QRCode
  
  
# Change your content here
se = "www.se.com/"
  
# Create QR code
link = pyqrcode.create(se)
  
# Create and save in png file naming "sepic.png"
link.png('sepic.png', scale = 6)
Code for QR Code

Results:

Image file “sepic.png” generated at base location.

Result – QR Code

Open image and check with google lens

Result – Python Code

Note: If you are able to understand above code, you can leave this article here but if you want to learn about the reason of written lines, you can find it below.

Library Explanations:

import pyqrcode
import png
from pyqrcode import QRCode
Library Import
  • pyqrcode module is used here for QR code creation. Encoding methods for qr code generation in the library “pyqrcode” are as per required standard.
  • png library is used for saving created images in PNG format.

# Change your content here
se = “www.se.com/”

Next Line

URL link assigned in se variable.

# Create QR code
link = pyqrcode.create(se)
Next Line

QR code created using pyqrcode.create() and assigned in variable “link”.

# Create and save in png file naming "sepic.png"
link.png('sepic.png', scale = 6)
Last Line

Value assigned in variable “link” further saved with “link.png(‘sepic.png, scale = 6)”

If you have any queries regarding this article or if I have missed something on this topic, please feel free to add in the comment down below for the audience. See you guys in another article.

You can visit our home page for more python codes here.

Stay Connected Stay Safe. Thank you


Rahul Verma

17+ years of experience in software development, IoT, telecom, banking, finance, embedded systems, data science, machine learning, and artificial intelligence with multiple market leaders worldwide. I hope you found this blog post informative and helpful. Cheers!

0 Comments

Leave a Reply

Avatar placeholder

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