jwh-452951171

 

代码

#!/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,操作更方便哦

 

分类:

技术点:

相关文章:

  • 2021-10-20
  • 2021-12-12
  • 2021-12-12
  • 2021-12-12
  • 2022-12-23
  • 2021-12-12
  • 2021-12-02
猜你喜欢
  • 2021-12-12
  • 2021-12-12
  • 2021-12-12
  • 2021-12-12
  • 2021-11-04
  • 2021-12-19
相关资源
相似解决方案