Generate QR Code with Python in just 5 lines of Code

Generate QR Code with Python

Python is a very powerful programming language. You can do almost anything you think with python. In this article, you learn about how to Generate QR Code with Python. So, without wasting time let's start.




Share this article on social media platforms if you like our content. Also, in case of any doubt you can ask it in the comments below.

Now, let's start with installing the pyqrcode module which will convert our string to a QR Code.

Also Read - To Do App with Django and Bootstrap


Installing Pyqrcode - First thing you have to do is to install the pyqrcode module. For this write the following command in your command prompt or terminal and hit enter to execute.

pip install pyqrcode

The module will be installed in few seconds.

Now, create a python file in which we will the write the code to generate the QR Code. 

1) Importing essential modules

import pyqrcode
from pyqrcode import QRCode

2) Create string which will represent the QR Code

s = "https://www.youtube.com/c/bhavikagarwal"



3) Now, let's generate the QR Code using the following command.

qr = pyqrcode.create(s)

4) Now, our qr code is generated and stored in qr variable. Let's create and save the svg file with name "myyt.svg".

qr.svg("myyoutubechannel.svg",scale = 7)

Here we finish with the code and now let's run the program.

After running the program, you will find that a .svg file named "myyt.svg" has been created in the same directory where this python file is present.

And when you will open that file, BOOM!! you will find the QR Code is generated. You can see the pic of QR Code below. When you will scan it, you will be able to see the link of my YouTube channel that I written in that string s.


Here is the complete source code to Generate QR Code with Python.

Source Code

import pyqrcode
from pyqrcode import QRCode

#String that represent the QR Code
s = "https://www.youtube.com/c/bhavikagarwal"

#Genreating QR Code
qr = pyqrcode.create(s)

#Saving QR Code in .svg format
qr.svg("myyt.svg",scale = 7)


I hope you liked the article about How to Generate QR Code with Python. In case of any doubt you can ask in the comments below. Also, your appreciation and suggestions are welcomed in the comment box.

Enjoy Coding!!!


Also Read 



For any doubts feel free to ask in comments below.
Stay Connected to Us for more such Courses and Projects.

Post a Comment

For any doubts feel free to ask in comments below.
Stay Connected to Us for more such Courses and Projects.

Post a Comment (0)

Previous Post Next Post