我编写了一个将docx转换为pdf的脚本。
我用tkinter制作了一个简单的表格。
当我尝试使用以下命令构建exe文件时:
pyinstaller --onefile converter.py
我还尝试了以下命令:
pyinstaller --noconsole converter.py
执行脚本转换器失败,我得到一个错误
import os
import tkinter as tk
from docx2pdf import convert
from tkinter.messagebox import showinfo
from tkinter.filedialog import askopenfilenames
def openfile():
try:
files = askopenfilenames(filetypes=[('word file', '*docx')])
for file in files:
convert(file, str(os.path.dirname(file)))
showinfo('Done', 'Files converted')
except Exception as e:
print('Error', e)
def main():
win = tk.Tk()
label = tk.Label(win, text='Choose file: ')
label.grid(row=0, column=0, padx=5, pady=5)
button = tk.Button(win, text='Select', width=30, command=openfile)
button.grid(row=0, column=0, padx=5, pady=5)
win.mainloop()
if __name__ == '__main__':
main()