Generating Static and Animated QR Codes with Python MyQR Library
This tutorial demonstrates how to install the MyQR Python library, explains its key parameters, and provides step‑by‑step code examples for creating static QR codes, adding background images, and producing animated QR codes using .gif files.
1. Code Practice
1.1 Module Installation
Install the required library with the command:
pip install MyQR1.2 Parameter Explanation
The main parameters of MyQR are:
words : content of the QR code
version : size of the QR code, range [1,40]
picture : background image file (.jpg, .png, .bmp, .gif); default is black‑white
colorized : background color flag, default False (black‑white)
save_name : output file name, default qrcode.png save_dir : directory to save the file, default is the current working directory
1.3 Code Practice
1.3.1 Static QR Code
Simple example to generate a QR code:
# -*- coding:utf-8 -*-
# @Time : 2021-09-30
# @Author : carl_DJ
from MyQR import myqr
# Define QR code content
word = "Carl"
# Generate QR code
myqr.run(word)Running the script creates qrcode.png in the current directory.
Resulting QR code image:
1.3.2 Adding a Background Image
Prepare a background picture and modify the code:
# -*- coding:utf-8 -*-
# @Time : 2021-09-30
# @Author : carl_DJ
from MyQR import myqr
word = "Carl"
myqr.run(
word,
picture='./wf.png',
colorized=True,
version=6
)The generated QR code now includes the specified background image.
1.3.3 Animated QR Code
To create an animated QR code, simply replace the background image with a .gif file:
# -*- coding:utf-8 -*-
# @Time : 2021-09-30
# @Author : carl_DJ
from MyQR import myqr
word = "miss U "
myqr.run(
word,
picture='./sohucs.gif',
colorized=True,
version=6
)The output is an animated QR code that cycles through the frames of the provided GIF.
In summary, generating both static and animated QR codes with MyQR only requires adjusting the picture parameter (using .png for static and .gif for animated) while keeping other arguments unchanged.
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.
