Installing and Using the MyQR Python Library to Generate QR Codes
This tutorial explains how to install the MyQR library, import it in PyCharm, and use its functions to create standard, image‑based, and colorized QR codes in Python, while also providing an overview of advanced parameters for further customization.
Download and Install myqr Library
Open the command prompt (Windows+R, then type cmd) and run the following command in a Python 3 environment: pip install myqr Wait until the installation completes successfully.
Import myqr Library
In PyCharm, open File → Settings → Project → Python Interpreter , click the + button, search for MyQr, select the first result and click Install Package. After installation, you can start using the library.
1. Generate a Simple QR Code
First import the library (note the case sensitivity): from MyQr import myqr # 注意大小写 Then generate a QR code with a URL or text: myqr.run(words='https://baidu.com') The QR code image ( qrcode.png) will be saved in the directory where the script is executed.
2. Generate a QR Code with a Custom Image
Add the picture argument to embed an image into the QR code:
from MyQR import myqr
myqr.run(
words='https://baidu.com',
picture='C:\Users\jinyj\Desktop\p1.png' # or use raw string r'C:\...'
)3. Generate a Colorized QR Code
Set colorized=True to produce a colored QR code:
from MyQR import myqr
myqr.run(
words='https://baidu.com',
picture='C:\Users\jinyj\Desktop\p1.png',
colorized=True
)4. Advanced Parameters (Optional)
The myqr.run() function supports many additional arguments for fine‑tuning:
from MyQR import myqr
myqr.run(
words='URL or text (no Chinese characters)',
version=5, # error correction capacity
level='H', # error correction level (L, M, Q, H)
picture='image.png', # can be a static image or GIF
colorized=True,
contrast=1.0,
brightness=1.0,
save_name='custom_qr.png',
save_dir=r'C:\Users'
)These parameters allow you to control the QR code size, error correction level, embedded picture, color mode, contrast, brightness, output filename, and storage location.
5. Animated QR Code
You can also use an animated GIF as the picture argument; the process is identical to the static image case.
For more details, refer to the original article linked below.
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.
