Search
  • English
Login Register
  • Mon - Sat 11.00 am - 8:00 pm
  • 1st-29, Atlanta Business Hub, VIP Road, Surat
  • +91 97129 28220
Code and Debug
  • Offline Courses
    • C Programming
    • Cpp Programming
    • Django Framework
    • Flutter Development
    • HTML & CSS
    • Javascript
    • MySQL
    • Node.js (Core)
    • Node.js (Advance)
    • Python Programming
  • About Us
  • Contact Us
  • Blog
  • Offline Courses
    • C Programming
    • Cpp Programming
    • Django Framework
    • Flutter Development
    • HTML & CSS
    • Javascript
    • MySQL
    • Node.js (Core)
    • Node.js (Advance)
    • Python Programming
  • About Us
  • Contact Us
  • Blog
Code and Debug > Blog > Project > Python Project > Mini Python Project > QR Code Generator with Python

QR Code Generator with Python

  • November 7, 2022
  • Posted by: Code and Debug
  • Category: Mini Python Project Project
No Comments

In this blog, we will learn how to generate QR Code using Python with help of qrcode module.

What is a QR Code?

Often when transacting with digital wallets, we scan the QR Code. Not just any code, QR Code is able to speed up and simplify the transaction process. The existence of a QR Code supports cardless transactions which are now echoed everywhere. Exactly what is a QR Code and how does it work?

QR Code is a matrix code or two-dimensional barcode derived from the word “Quick Response”, where the contents of the code can be deciphered quickly and precisely.

Steps to install qrcode module

  • Install qrcode library
				
					pip install qrcode
				
			
  • Import qrcode
				
					import qrcode
				
			

Basic Usage

Refer the code below to generate a basic QR Code.

				
					import qrcode

img = qrcode.make("https://codeanddebug.in")
img.save("myQRcode.png")
				
			

A file with name myQRcode.png will be generated within the same folder.

Some more usage of qrcode module

Above, we created a QR code in its default form with default parameters, now we will try to give color, box size, border and more to our QR code.

				
					import qrcode

qr = qrcode.QRCode(error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=15, border=2)
qr.add_data('https://codeanddebug.in')
qr.make(fit=True)
img = qr.make_image(fill_color="black", back_color="purple")
img.save("myQRcode2.png")
				
			
  • ERROR_CORRECT_L: up to 7% or less errors can be corrected.
  • ERROR_CORRECT_M: up to 15% or less errors can be corrected.
  • ERROR_CORRECT_Q: up to 25% or less errors can be corrected.
  • ERROR_CORRECT_H: up to 30% or less errors can be corrected.

A file with name myQRcode2.png will be generated within the same folder.

Adding round style to QR Code

We can style our QR Code using the StyledPilImage submodule.

				
					import qrcode
from qrcode.image.styledpil import StyledPilImage
from qrcode.image.styles.moduledrawers import RoundedModuleDrawer

qr = qrcode.QRCode(error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=15, border=2)
qr.add_data('https://codeanddebug.in')
qr.make(fit=True)
img = qr.make_image(image_factory= StyledPilImage, module_drawer=RoundedModuleDrawer())
img.save("myQRcode3.png")
				
			

A file with name myQRcode3.png will be generated within the same folder.

Adding gradient style to QR Code

We can style our QR Code using the RadialGradiantColorMask submodule.

				
					import qrcode
from qrcode.image.styles.colormasks import RadialGradiantColorMask

qr = qrcode.QRCode(error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=15, border=2)
qr.add_data('https://codeanddebug.in')
qr.make(fit=True)
img = qr.make_image(image_factory= StyledPilImage, color_mask=RadialGradiantColorMask())
img.save("myQRcode4.png")
				
			

A file with name myQRcode4.png will be generated within the same folder.

code miniproject python

Leave a Reply Cancel reply

About US

At Code & Debug, our mission is to continuously innovate the best ways to train the next generation of developers and to transform the the way tech education is delivered.

Code & Debug was founded in 2020 to bridge the knowledge gap between colleges and industry. Founded by Anirudh Khurana, Code & Debug has professional teaching faculty and a state-of-art learning platform for Coding education.
View Courses

Pages

  • About Us
  • Contact Us
  • Home
  • Offline Courses
  • User Account

Contact Us

  • 1st-29, Atlanta Business Hub, VIP Road, Surat
  • Tel.: +91 97129 28220
  • info@codeanddebug.in