CodeSolved

Solved Programming Questions & Exercises

Making QR Code

Practice Easy 1778/ Download 165 Views

Write a program that receives a URL or text and converts it to a QR Code and saves with a PNG extension.

2 Answers

import qrcode

def generate_qr_code(data, filename="qrcode.png"):
    # Construction of the qr code object
    qr = qrcode.QRCode(
        version=1,  # Code size (1 to 40)
        error_correction=qrcode.constants.ERROR_CORRECT_H,  # Error correction level
        box_size=10,  # The size of each small square in pixel
        border=4,  # Border thickness
    )

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

    # Creating QR Code Image
    img = qr.make_image(fill_color="black", back_color="white")

    # PNG image save
    img.save(filename)
    print(f"QR code saved as {filename}")

# Example use
if __name__ == "__main__":
    user_input = input("Enter URL or text to convert to QR code: ")
    generate_qr_code(user_input, "my_qrcode.png")
Sumy.amiri Download Python
OS module to save file as PNG and QRCODE module to build kwarcod.
import qrcode as qr 
import os
data= input(f'Entger the message to be encoded :')
img=qr.make(data)
img.save('myqr.png')
os. system('myqr.png')

Submit answer

Submitting answers is currently unavailable.

×
×
Close