python: generate and decode QrCode

 

pip install pyzbar
pip install PyQRCode
pip install qrcode
pip install Pillow

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# 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

  

调用:

1
2
3
4
nowpath = os.getcwd() #当前项目文件夹
generateQrCode(r"http://www.dusystem.com","geovindu")
codedata=readQrCode("geovindu")
print("qrcode:",codedata)

  

posted @   ®Geovin Du Dream Park™  阅读(15)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
历史上的今天:
2014-07-08 csharp: QR Code Barcode
2011-07-08 sql server 2005 输出表的函數用法
2011-07-08 SQL server 2005 表中某一字段的所有值逗号分开的列表
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示