如何从Python脚本中独立执行,该脚本接受输入并使用PyInstaller生成Word文档

时间:2019-02-14 04:53:29

标签: python tkinter pyinstaller mailmerge

我正在尝试创建一个独立的可执行文件(一个文件)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”

0 个答案:

没有答案