Creating Custom QR Codes with Python for Easy Sharing
Written on
Chapter 1: Introduction to QR Codes
In the modern digital landscape, the need for swift information exchange is more crucial than ever. Many companies have recognized that mobile devices are the go-to for quick access to information and have adopted QR codes for sharing contact details, menus, and more. This article explores how to create a personalized QR code using Python that links directly to a LinkedIn profile.
Developing the Program
Although QR codes can store various types of data, the easiest way to begin is by encoding a URL. First, we need to install and import the necessary libraries to generate a custom QR code and save it as a PNG file.
To start, install the libraries using pip. If you face any issues with pip, consider using pip3:
pip install pyqrcode
pip install pypng
Next, import these libraries into your Python script:
import pyqrcode
import png
Now, we will prompt the user for input so the QR code can direct users to a specific URL:
file_name = input('Enter the name of the QR code: ')
website = input('Enter the link to your website: ')
We can then store this input in a variable named qr_data and generate the QR code using the pyqrcode library:
qr_data = website
qr_code = pyqrcode.create(qr_data)
Having created the QR code, we now need to save it as a PNG file, which can be utilized in various contexts. We'll also include a print statement to confirm the successful creation of the QR code and PNG file:
file_name_png = file_name + '.png'
qr_code.png(file_name_png, scale=4)
print("Generated QR code")
Upon executing the program, you will generate a QR code. Scan it to explore more about my work. Here’s an example linked to Aviral Mehrotra's LinkedIn profile.
Full Code — 12 Lines!
import pyqrcode
import png
file_name = input('Enter the name of the QR code: ')
website = input('Enter the link to your website: ')
qr_data = website
qr_code = pyqrcode.create(qr_data)
file_name_png = file_name + '.png'
qr_code.png(file_name_png, scale=4)
print("Generated QR code")
This concise yet effective Python script demonstrates how swiftly you can create QR codes for sharing information. The concepts discussed here can be seamlessly integrated into larger projects.
Have you ever experimented with QR codes? Do you consider them the future of business cards? Feel free to share your thoughts or questions in the comments!
Thank you for being part of the community! Before you go: Clap for this article and follow the writer! Follow 20 Lines or Less for more engaging content!
Chapter 2: Exploring QR Code Applications
Discover how to create QR codes and their potential applications in various settings. This video covers the basics of QR code creation and effective uses.
Learn how to integrate QR codes into classroom activities, enhancing learning experiences and information sharing.