#报错信息
Exception in Tkinter callback
Traceback (most recent call last):
File "tkinter_init_.py", line 1921, in call
File "a1.py", line 29, in cz_cli
File "barcode\base.py", line 65, in save
File "barcode\codex.py", line 257, in render
File "barcode\base.py", line 105, in render
File "barcode\writer.py", line 227, in render
File "barcode\writer.py", line 372, in _paint_text
File "PIL\ImageFont.py", line 878, in truetype
File "PIL\ImageFont.py", line 875, in freetype
File "PIL\ImageFont.py", line 226, in init
OSError: cannot open resource
#报错代码
from pystrich.code128 import Code128Encoder
import openpyxl
import barcode
import os
from barcode.writer import ImageWriter
from openpyxl.drawing.image import Image
import tkinter
import winreg
#获取系统桌面路径
def get_desktop():
key = winreg.OpenKey(winreg.HKEY_CURRENT_USER,
r'Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders')
return winreg.QueryValueEx(key, "Desktop")[0]
Desktop_path=str(get_desktop())
wbb=openpyxl.Workbook()
wbb.create_sheet(title='打印',index=0)
wbb.save(Desktop_path+'/打印表.xlsx') # 保存
barcode.writer.FONT=os.path.join('AdobeGothicStd-Bold.otf')
def cz_cli():
#生成条形码保存为图片
bm='123456789'
tm = barcode.get_barcode_class('code128')
tmgs=tm(bm, writer=ImageWriter())
#条形码间距,文本与条码间距,文本尺寸,分辨率
tmgs.save(Desktop_path+'/code128',{'module_width':0.3,'text_distance':0.5,'font_size':20,'dpi':200})
#加载图片到EXCEL
wb = openpyxl.load_workbook(Desktop_path+'/打印表.xlsx')
ws = wb['打印']
img=Image(Desktop_path+'/code128.png')
ws.add_image(img,'B1')
wb.save(Desktop_path+'/打印表.xlsx')
dl_win = tkinter.Tk()
dl_win.title('登录窗口')
dl_win.geometry('%dx%d+%d+%d' % (300, 210, 100, 100))
cz_b = tkinter.Button(dl_win, text='生成', width=8, command=cz_cli)
cz_b.place(x=60, y=40)
dl_win.mainloop()