安装命令:pip install pyStrich
import os
import time
import sys
from pystrich.code128 import Code128Encoder
from pystrich.ean13 import EAN13Encoder
from pystrich.qrcode import QRCodeEncoder
def code128():
code = input("输入条码code128:")
if code == "exit":
sys.exit()
else:
encoder = Code128Encoder(code)
encoder.save("1.png", bar_width=6)
os.system("1.png")
time.sleep(2)
os.remove("1.png")
return code128()
def ean13():
code = input("输入条码ean13:")
if code == "exit":
sys.exit()
elif len(code) < 12 or len(code) > 13:
print('★★输入ean13条码有误★★')
else:
if code.isdigit() == True: # 判断是否为数字
encoder = EAN13Encoder(code)
encoder.save("2.png", bar_width=4)
os.system("2.png") #用系统默认看图软件打开图片
time.sleep(2)
else:
print("请输入数字")
return ean13()
def qrcode():
code = input("输入条码qrcode:")
if code == "exit":
sys.exit()
else:
encoder = QRCodeEncoder(code)
encoder.save("3.png", cellsize=15)
os.system("3.png")
time.sleep(5)
os.remove("3.png")
return qrcode()
if __name__ == "__main__":
# code128()
ean13()
# qrcode()