Generate QR Code in Python

Generate QR code in python using "qrcode" library

import qrcode # pip install qrcode

data = "youtube.com/@computergeek7442"
img = qrcode.make(data)
img.save("myqrcode.png")

# For more control use this method

def qrcode_generate(data):
    # create an object of QRCode class
    qr = qrcode.QRCode(
        version=1, # controls the size of the QR Code (1 to 40) the smallest is version 1
        error_correction = qrcode.constants.ERROR_CORRECT_L, # controls the error correction
        # four constants available on the qrcode package:
        # ERROR_CORRECT_L About 7% or less errors can be corrected
        # ERROR_CORRECT_M (default) About 15% or less errors can be corrected
        # ERROR_CORRECT_Q About 25% or less errors can be corrected
        # ERROR_CORRECT_H About 30% or less errors can be corrected
        box_size=10,
        border=4 # controls how many boxes thick the border should be (the default is 4, which is the minimum according to the specs).
        )
    
    qr.add_data(data)
    qr.make(fit=True) # ensures that the entire dimension of the QR Code is utilized
    img = qr.make_image(fill_color="black", back_color="white")
    img.save("qrcode001.png")
    
text_or_url = input("Plz enter text or URL to encode into QR code: ")
qrcode_generate((text_or_url))
   

    

Comments

Popular posts from this blog

Quotation marks to wrap an element in HTML

The Basic Structure of a Full-Stack Web App

Unlocking Web Design: A Guide to Mastering CSS Layout Modes