Making QR Code
Write a program that receives a URL or text and converts it to a QR Code and saves with a PNG extension.
Write a program that receives a URL or text and converts it to a QR Code and saves with a PNG extension.
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")
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')
Submitting answers is currently unavailable.
برای استفاده از این بخش باید وارد حساب کاربریت بشی
ورود/ثبت نام If you don’t understand the exercise or can’t solve it for any reason, that’s completely
normal—don’t worry 😊
Try checking out easier exercises and reviewing different answers
submitted by others. Gradually, you can move on to more challenging exercises. Also, your answer
might be correct even if it’s different from others.