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()
将字符串转换为条形码
最新推荐文章于 2024-08-30 10:24:42 发布