Python 带可视化页面的条形码(code128)生成器。

代码

#!/usr/bin/python
# -*- coding: UTF-8 -*-

from tkinter import *  # 导入 Tkinter 库
import barcode
import datetime
from barcode.writer import ImageWriter
from PIL import *
from PIL import ImageTk

def create_barcode(code):
    if not code.get():
        return
    CODE128 = barcode.get_barcode_class('code128')
    bar_code = CODE128(code.get(), writer=ImageWriter())
    bar_photo = ImageTk.PhotoImage(bar_code.render())
    imgLabel.config(image=bar_photo)
    imgLabel.image = bar_photo

root = Tk()  # 创建窗口对象的背景色

root.title('条形码生成器')
root.geometry('800x400')

enter_code = StringVar()

bar_code_input = Entry(root, textvariable=enter_code)
bar_code_input.pack()

btn = Button(root, text='确认', command=lambda: create_barcode(enter_code))
btn.pack()

imgLabel = Label(root)
imgLabel.pack()
root.mainloop()  # 进入消息循环

使用pyinstaller打包

运行时,需要将barcode下的ttf字体文件复制到:C:\Windows\Fonts,否则无法生成条形码

链接:https://pan.baidu.com/s/16na1oqhuLTNk_PBaLeNTCA
提取码:ojss
复制这段内容后打开百度网盘手机App,操作更方便哦

猜你喜欢

转载自www.cnblogs.com/jwh-452951171/p/11023806.html