By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
rocoderesrocoderes
  • Home
  • HTML & CSS
    • Login and Registration Form
    • Card Design
    • Loader
  • JavaScript
  • Python
  • Internet
  • Landing Pages
  • Tools
    • Google Drive Direct Download Link Generator
    • Word Count
  • Games
    • House Painter
Notification Show More
Latest News
How to set the dropdown value by clicking on a table row
Javascript – How to set the dropdown value by clicking on a table row
JavaScript
Attempting to increase the counter, when the object's tag exist
Javascript – Attempting to increase the counter, when the object’s tag exist
JavaScript
Cycle2 JS center active slide
Javascript – Cycle2 JS center active slide
JavaScript
Can import all THREE.js post processing modules as ES6 modules except OutputPass
Javascript – Can import all THREE.js post processing modules as ES6 modules except OutputPass
JavaScript
How to return closest match for an array in Google Sheets Appscript
Javascript – How to return closest match for an array in Google Sheets Appscript
JavaScript
Aa
Aa
rocoderesrocoderes
Search
  • Home
  • HTML & CSS
    • Login and Registration Form
    • Card Design
    • Loader
  • JavaScript
  • Python
  • Internet
  • Landing Pages
  • Tools
    • Google Drive Direct Download Link Generator
    • Word Count
  • Games
    • House Painter
Follow US
High Quality Design Resources for Free.
rocoderes > Python > How To Make Python QR Code Generator
Python

How To Make Python QR Code Generator

Admin
Last updated: 2022/11/25 at 5:46 AM
Admin
Share
5 Min Read
python QR code generator

In this article, we will learn a python QR code generator using the pyqrcode library. Python has different libraries to generate QR codes, like – qrcode, PyQRCode, PyQRCodeNG, qrcodegen, Sengo. Each library has its own advantages.

Contents
What is a QR code?QR code Library in Python (pyqrcode)Output of QR code Generator:Create QRCode image in png formatFull Source Code Of Python QR Code GeneratorYou may also like:

pyqrcode module is a QR code generator. The module automates most of the building process for creating QR codes. This module attempts to follow the QR code standard as closely as possible. The terminology and the encodings used in pyqrcode come directly from the standard.

What is a QR code?

A QR (quick response) code is a box-shaped matrix form of a 2-dimensional barcode (also called checkerboard-type barcode) that contains some meaningful data or linkage. It is frequently employed on mobile apps and websites nowadays. As compared to the traditional barcodes, these data can store more information. Such code renders a certain box-type pattern across it for recording meaningful data or a large set of information in a black and white pattern.

QR code was invented by a Japanese engineer Masahiro Hara from automobile manufacturer Denso Wave in the year 1994 to track the movement of car parts.
QR Code has increased in popularity in the later 2010s with improvement in optical capabilities of mobile phones and their wide adoption.

Such a code remains distributed on a 2D plane. It can hold numbers, English alphabets, Japanese letters, Chinese characters, special symbols (Unicode and ASCII), binary information, and other information within that square image. The corresponding appearance of dots (square dots or other shapes) represents binary “1”, and the absence of these dots or white/blank spaces represents binary “0”. A QR code leverages a permutation and a combination technique to determine the meaning of the matrix two-dimensional bar code.

image source By :stechies

QR code Library in Python (pyqrcode)

pip install pyqrcode

Once you have successfully installed the pyqrcode library. At First, we have imported the pyqrcode module and used the create() method to generate the code.

Syntax of QRCode create() method –

pyqrcode.create(content, error='H', version=None, mode=None, encoding=None)

When creating a QR code only the content to be encoded is required, all the other properties of the code will be guessed based on the contents given. This function will return a QRCode object.

One can specify all the properties of the required QR code through the optional parameters of the pyqrcode.create() function. Below are some properties:

error: This parameter sets the error correction level of the code.
version: This parameter specifies the size and data capacity of the code.
mode: This parameter sets how the contents will be encoded.

In the given example, we have passed the string as an argument to this method and used the svg() method to store it in svg file format.

# Import QRCode from pyqrcode 
import pyqrcode 
from pyqrcode import QRCode 
  
# URL string
site = "www.rocoderes.com"
  
# Generate QR code 
getqrcode = pyqrcode.create(site) 
  
# save in svg file format
getqrcode.svg("qrcode.svg", scale = 8) 

Output of QR code Generator:

When you execute the above file, it will generate and save the file in your project directory. 

Python QR Code Generator

Create QRCode image in png format

Python provides a pypng library to read and write on png file images. If we want to save the generated QRcode in a png file, we will have to install this library.

Run the following command to install ‘pypng’ library

pip install pypng

Here is the code to generate qrcode and save it in a png file.


import pyqrcode
import png 
from pyqrcode import QRCode 
  
# URL string
site = "www.rocoderes.com"
  
# Generate QR code 
getqrcode = pyqrcode.create(site) 
  
# save in svg file format
getqrcode.svg("qrcode.svg", scale = 8) 

# save in the png file
getqrcode.png("qrcode.png", scale = 6)

Full Source Code Of Python QR Code Generator

import pyqrcode
import png 
from pyqrcode import QRCode 
  
site = "www.rocoderes.com"
getqrcode = pyqrcode.create(site) 
getqrcode.svg("qrcode.svg", scale = 8) 
getqrcode.png("qrcode.png", scale = 6)

You may also like:

  • Convert Images Into Pencil Sketch Using Python
  • picture matching game using python
  • Hangman in Python
  • Tic-Tac-Toe Game Using Python

Related

Subscribe to Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

TAGGED: Python QR Code Generator
Share this Article
Facebook Twitter Email Print
What do you think?
Love0
Sad0
Happy0
Sleepy0
Angry0
Dead0
Wink0
Posted by Admin
Follow:
Rocoderes is a blog you can learn HTML, CSS, JavaScript, React Js and Python along with creative coding stuff and free source code files.
Previous Article Plants Website Design How To Make Plants Website Design
Next Article Automatic image slider in html css How to Make Automatic Image Slider in JavaScript
Leave a comment Leave a comment

Leave a Reply Cancel reply

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

- Advertisement -

You Might Also Like

Rock Paper Scissors Python

How To Make Rock Paper Scissors Python Game 2022

November 26, 2022
Countdown Calendar using Python Tkinter

How to Make Countdown Calendar using Python Tkinter

November 24, 2022
binary search algorithm in python

What is Binary Search Algorithm in python?

November 23, 2022

What is Linear search in python?

November 23, 2022
rocoderesrocoderes
Follow US

Copyright © 2022 All Right Reserved By Rocoderes

  • Home
  • About us
  • Contact us
  • Disclaimer
Join Us!

Subscribe to our newsletter and never miss our latest news, podcasts etc.

Zero spam, Unsubscribe at any time.
Welcome Back!

Sign in to your account

Lost your password?