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 in a variable.
  3. Now pass this variable into qrcode.make() and save the QR image.

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

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

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

Share your love
Subhankar Rakshit
Subhankar Rakshit

Hey there! I’m Subhankar Rakshit, the brains behind PySeek. I’m a Post Graduate in Computer Science. PySeek is where I channel my love for Python programming and share it with the world through engaging and informative blogs.

Articles: 147