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 in a variable.
- Now pass this variable into qrcode.make() and save the QR image.
👉Visit Also: Create QR Code Scanner in Python
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
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