How to create QR code in Python
What is a QR Code in nutshell?
A Quick Response code is a two-dimensional pictographic code used for its fast readability and comparatively large storage capacity. The code consists of black modules arranged in a square pattern on a white background. The information encoded can be made up of any kind of data (e.g., binary, alphanumeric)
its very simple on console (tested on mac, debian and ubuntu latest OS)
below command will install all required module including pil (Python Imaging Library):pillow
pip install qrcode[pil]
then
Usage form command line
qr "Some text" > image_name_with_extention
qr "makerspacekanpur.com" > msk.png
or
Sample example to generate QR code and save in png file in python.
import qrcode qr = qrcode.QRCode( version=1, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=10, border=4, ) qr.add_data('https://makerspacekanpur.com') qr.make(fit=True) img = qr.make_image(fill_color="black", back_color="white") img.save('msk-site.png')
Sample example to instant preview of QR code in python.
import qrcode qr = qrcode.QRCode( version=1, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=10, border=4, ) qr.add_data('Some data') qr.make(fit=True) img = qr.make_image(fill_color="black", back_color="white") img.show()
source : Python.org
join our python training in kanpur for Zero to Hero in Python.
Leave a Reply
You must be logged in to post a comment.