def write_chart(calculate_data, title_data, address):
workbook = load_workbook(address)
sheet = workbook['Summary_Data']
# 将图片写入Excel
for m in range(len(calculate_data)):
chart_title = title_data[m]
image = Image('./Photo/{0}的过程能力报告.png'.format(chart_title))
image.width = 450
image.height = 328
sheet.add_image(image, anchor='J' + str(m * 15 + 1))
老师,我结合openpyxl和Tkinter,将图片插入Excel中,单独运行时可以的,但是一在TKinter中运行就会报错,路径下的图片是存在的,是什么原因啊
报错如下:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\wenhaoxu\AppData\Local\Programs\Python\Python37\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "F:\PythonProject\DataCalculate.py", line 17, in select
write_chart(a, d, y)
File "F:\PythonProject\DataCalculate.py", line 197, in write_chart
image = Image('./Photo/{0}的过程能力报告.png'.format(chart_title))
File "C:\Users\wenhaoxu\AppData\Local\Programs\Python\Python37\lib\tkinter\__init__.py", line 3501, in __init__
self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: image type "./Photo/MTF_0的过程能力报告.png" doesn't exist