Introduction
In the previous post, we had studied how to generate and decode QR codes using python. In this tutorial, you'll learn how to convert a text file to a QR code using only a few lines of python code.
Just follow these simple steps given below.
- Open the text file in the read mode that you want to convert. (Check file handling in python)
- Read the data from the file and store it into a variable.
- Now pass this variable into qrcode.make() and save the QR image.
Yes, you have done!
🍁Visit Also: Create QR Code Scanner in Python - Scan through the WebCam
Requirement and Installation
qrcode: pip install qrcode
Code👇
import qrcode
with open('text_file.txt') as f:
data = f.read()
img = qrcode.make(data)
img.save('secret.png')
Output
Task for You
Download the image generated by the above code and decode that. Let me know in the comment section what you've found from it.
That's all for this tutorial. Please feel free to drop your comment below. You'll get a reply soon.
Thanks for reading!💙
🍁Visit Also: How to Convert Speech to Text in Python