python: generate and decode QrCode
pip install pyzbar
pip install PyQRCode
pip install qrcode
pip install Pillow
# encoding: utf-8
#-*- coding: UTF-8 -*-
# 版权所有 2023 ©涂聚文有限公司
# 许可信息查看:
# 描述:
# Author : geovindu,Geovin Du 涂聚文.
# IDE : PyCharm 2023.1 python 311
# Datetime : 2023/7/5 11:08
# User : geovindu
# Product : UI
# Project : pythonTkinterDemo
# File : main.py
# explain : 学习
import pyzbar.pyzbar as p
import pyqrcode
import qrcode
def generateQrCode(qrcodestr:str,qrcodefile:str):
"""
生成二维码
:param qrcodestr: 二要生成的二给码字符
:param qrcodefile: 生成的文件名
:return:
"""
img = qrcode.make(qrcodestr)
type(img)
img.save(r'{qrcodefile}.png')
def readQrCode(qrcodefile:str):
"""
读二维码
:param qrcodefile: 二维码文件名
:return: 返回二维码内容
"""
nowpath = os.getcwd()
scrimg=Image.open(r"{nowpath}\{qrcodefile}.png")
m=p.decode(scrimg)
codedata=m[0].data.decode("utf-8")
return codedata
调用:
nowpath = os.getcwd() #当前项目文件夹
generateQrCode(r"http://www.dusystem.com","geovindu")
codedata=readQrCode("geovindu")
print("qrcode:",codedata)
哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)生存.---Geovin Du(涂聚文)
浙公网安备 33010602011771号