Create Custom QR Codes in Python with MyQR – A Step‑by‑Step Guide
This tutorial walks you through installing the MyQR library, importing it in PyCharm, and generating plain, image‑based, and colored QR codes with Python, while also providing a full list of configurable parameters for advanced customization.
1. Install MyQR library
Open the command prompt (Windows+R, then type cmd) and run: pip install myqr Wait until the installation completes successfully.
2. Import MyQR in PyCharm
In PyCharm go to File → Settings → Python Interpreter , click the + button, search for MyQR, select the first result and click Install Package . After installation you can import the library in your code:
from MyQR import myqr3. Generate a plain QR code
Use the following code to create a simple QR code that encodes a URL or text: myqr.run(words='https://baidu.com') The generated file qrcode.png will appear in the same directory as your script.
4. Generate a QR code with a custom picture
Add the picture argument to embed an image into the QR code:
myqr.run(
words='https://baidu.com',
picture='C:\Users\jinyj\Desktop\p1.png'
)5. Generate a colored QR code
Set colorized=True to produce a colored QR code (requires a custom picture as well):
myqr.run(
words='https://baidu.com',
picture='C:\Users\jinyj\Desktop\p1.png',
colorized=True
)6. Extended parameters
MyQR offers many additional options for fine‑tuning the output. Below is a comprehensive example:
myqr.run(
words='https://example.com',
version=5, # error correction level
level='H', # L, M, Q, H (increasing redundancy)
picture='logo.png', # path to an image (can be GIF)
colorized=True, # True for color, False for black‑white
contrast=1.0, # image contrast
brightness=1.0, # image brightness
save_name='custom_qr.png',
save_dir=r'C:\Users'
)These parameters let you control the QR code size, error correction, embedded image, colorization, contrast, brightness, and output location.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Python Programming Learning Circle
A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
