Convert Text File to QR Code using Python

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.

  1. Open the text file in the read mode that you want to convert. (Check file handling in python)
  2. Read the data from the file and store it into a variable.
  3. Now pass this variable into qrcode.make() and save the QR image.

Yes, you have done!

👉Visit AlsoCreate 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

Convert text file to QR Code using a few lines of python code.

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 AlsoHow to Convert Speech to Text in Python

Subhankar Rakshit

Meet Subhankar Rakshit, a Computer Science postgraduate (M.Sc.) and the creator of PySeek. Subhankar is a programmer, specializes in Python language. With a several years of experience under his belt, he has developed a deep understanding of software development. He enjoys writing blogs on various topics related to Computer Science, Python Programming, and Software Development.

Post a Comment (0)
Previous Post Next Post