我正在尝试创建一个独立的可执行文件(一个文件)python脚本,该脚本将用户输入,邮件合并成模板字并生成新文档
我阅读了各种问题,并认为临时文件(_MEIxxxxxx)可能存在问题,需要将其输入代码中。第二个问题是如何添加模板文件
from tkinter import *
from datetime import datetime
from mailmerge import MailMerge
import calendar
def clear():
# clear the content of text entry box
name_field.delete(0, END)
def generate():
name = str(name_field.get())
template = "Template.docx"
document = MailMerge(template)
document.merge(
Customer_name=name)
doc_name = name +'.doc'
document.write(doc_name)
window = Tk()
window.geometry("512x512")
window.resizable(0, 0)
window.title("Generate Individual Form")
heading = Label(window, text="Form", font=30)
heading.grid(row=0, column=1)
name_label = Label(window, text="Cust Name")
name_label.grid(row=1, column=0)
name_field = Entry(window)
name_field.grid(row=1, column=1, ipadx="100")
submit = Button(window, text="Generate Form", font=22, command=generate)
submit.grid(row=23, column=1)
window.mainloop()
要运行pystaller,我尝试了以下代码:
pyinstaller --onefile --add-data 'Template.docx' myscript.py
错误消息-“添加数据无效的add_data或二进制值“ Template.docx”