将字符串转换为条形码

import time

import barcode
from barcode.writer import ImageWriter
import threading,queue

# 更多了解:https://pypi.org/project/python-barcode/0.8.1/
# pip install python-barcode

# # 查看 python-barcode 支持的条形码格式
print(f"python-barcode支持的条形码格式:\n{barcode.PROVIDED_BARCODES}")
#
class qrcode(threading.Thread):
    def __init__(self,ssn):
        super().__init__()
        self.ssn = ssn
    def run(self):
        # # 创建条形码格式对象,参数为支持的格式
        EAN = barcode.get_barcode_class('code128')
        # 条形码内容
        message = self.ssn
        # 创建条形码对象
        ean = EAN(message, writer=ImageWriter())
        # 保存条形码图片,并且返回路径
        fullname = ean.save(f"C:\\Users\\Micheal_Ma\\Desktop\\code\\EAN\\{self.ssn}")
        print(f"条形码保存路径:{fullname}")

def test():
    ssnpath = r"C:\Users\Micheal_Ma\Desktop\code\test\ssn.txt"
    with open(ssnpath,'r')as ff:
        tt = ff.readlines()
    q = queue.Queue()
    for i in tt:
            if i.strip() != "":
                q.put(i.strip())
    for i in range(q.qsize()):
        for j in range(8):
            ssn = q.get()
            t = qrcode(ssn)
            t.start()
        time.sleep(0.1)
    print("--------------------end-----------------")
if __name__ == '__main__':
    test()
  • 4
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值