Create QR code using qrcode in python
We need to install qrcode module to create QR code using python. Use below command to install using pip.
pip install qrcode
Now let's check below code to create a png image with some sample data.
import qrcode
msg = "Welcome to Code Adhyayana!!!"
img_qr = qrcode.make(msg)
img_qr.save('sample.png')
Error: ModuleNotFoundError: No module named 'Image'
if you are getting above module not found error, while executing this code then you need to install PIL module using below command:
pip install Pillow
for conda users:
conda install -c anaconda Pillow
after installing Pillow, re-execute the code, this time you should get sample.png image with QR code. We can scan and validate if it's correct or not.
Let's check how we can create qrcode with custom color and size.
import qrcode
qr_obj = qrcode.QRCode(box_size = 20,
border = 2)
qr_obj.add_data("Welcome to Code Adhyayana")
qr_img = qr_obj.make_image(fill_color='yellow',
back_color='black')
qr_img.save('sample_4.png')
Usage:
- Create QR code to get user feedback using google form or any other service.
- Create QR code to share location in invitation card. Example wedding, party, interview.
- Create QR code with website url, So that instead of typing url we can simply scan.
Comments
Post a Comment