Introduction
In this tutorial, you'll learn How to Convert a Text File to a QR Code using only a few lines of Python Code. Before that, I would recommend you, learn how to generate and decode QR codes using python.
To complete today's task, we need to go through the following steps.
- 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
☛Install 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