Python Code for QR Code Generator – Easy Step-by-Step Tutorial for Beginners

Python code for qr code generator: QR codes are everywhere today. From restaurant menus and payment systems to website links and Wi-Fi sharing, QR codes make it easy to access information instantly. If you are learning Python and want to build a simple yet useful project, creating a QR code generator is one of the best beginner-friendly projects.

python code for qr code generator

In this tutorial, you will learn how to create a QR code generator using Python step by step. We will use a Python library called qrcode to generate QR codes quickly and efficiently.

  • By the end of this article, you will be able to:
  • Run the project on your computer
  • Install the required Python libraries
  • Write Python code to generate QR codes
  • Save QR codes as image files
  • Customize QR code size and colors
Article NamePython Code for QR Code Generator – Easy Step-by-Step Tutorial for Beginners
Publish Date8/5/2026
What ispython code for qr code generator
AuthorCodeswithsam

Python Code for Adding Two Numbers

What is a QR Code?

A QR code (Quick Response code) is a type of barcode that stores information such as:

  • Website URLs
  • Contact details
  • Text messages
  • Wi-Fi passwords

Why Use Python for QR Code Generation?

Python is one of the most popular programming languages because it is:

  • Perfect for mini projects
  • Easy to learn
  • Beginner-friendly
  • Powerful for automation
  • Rich in libraries and tools

Requirements

Before starting, make sure you have:

  • Basic knowledge of Python
  • Python installed on your system
  • Internet connection to install libraries

Install Required Library

We need the qrcode library to generate QR codes.

Open your terminal or command prompt and run:

pip install qrcode[pil]

This command installs:

Pillow (PIL) → Used for image processing

qrcode → Used for generating QR codes

Python Code for QR Code Generator

import qrcode

# Data to store in QR code
text = "https://codeswithsam.com"

# Create QR code instance
qr = qrcode.QRCode(
version=1,
box_size=10,
border=5
)

# Add data to QR code
qr.add_data(text)
qr.make(fit=True)

# Create image
img = qr.make_image(fill_color="black", back_color="white")

# Save image
img.save("qrcode.png")

print("QR Code generated successfully!")

How to Run the Project

Follow these simple steps:

Step 1: Install Python

Download and install Python.

Step 2: Install qrcode Library

Run:

pip install qrcode[pil]

Step 3: Create Python File

Create a file named:

qr_generator.py

Step 4: Paste the Code

Copy and paste the Python code into the file.

Step 5: Run the Program

Open terminal and run:

python qr_generator.py


Output

After running the program:

  • You can scan it using your smartphone
  • A QR code image will be generated
  • The image will be saved in your project folder

Advanced QR Code Generator Example

import qrcode

# User input
text = input("Enter text or URL: ")

# Generate QR code
img = qrcode.make(text)

# Save image
img.save("custom_qr.png")

print("Custom QR Code generated successfully!")

Real-World Applications of QR Codes

QR codes are used in many industries.

1. Digital Payments

Apps like Google Pay and Paytm use QR codes.

2. Website Sharing

Businesses use QR codes to share websites instantly.

3. Event Management

QR codes are used for tickets and passes.

4. Wi-Fi Sharing

Users can connect to Wi-Fi without typing passwords.

5. Product Information

Companies provide product details through QR codes.

Final Thoughts

In this tutorial, we learned how to create a QR code generator using Python. This is one of the easiest and most practical Python mini projects for beginners.

Using the qrcode library, you can generate QR codes for websites, text, payment links, and much more. This project is simple, useful, and a great addition to your Python portfolio.

If you want to learn more Python projects, keep visiting CodesWithSam.com for beginner-friendly coding tutorials.


Important Links

Our WebsiteCodeswithsam.com
Join TelegramClick Here

If we made a mistake or any confusion, please drop a comment to reply or help you in easy learning.

Thanks! 🙏 for visiting Codeswithsam.com ! Join telegram (link available in bottom) for source code files , pdf and
Any Promotion queries 👇
info@codeswithsam.com

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top