import tkinter as tk
from tkinter import filedialog, messagebox
from pdf2docx import Converter
def convert_pdf_to_docx():
pdf_file = pdf_entry.get()
docx_file = docx_entry.get()
cv = Converter(pdf_file)
cv.convert(docx_file, start=0, end=None)
cv.close()
messagebox.showinfo("提示", "文件转换完毕!")
messagebox.showinfo("提示", f"路径:{docx_file}")
def select_pdf_file():
pdf_file = filedialog.askopenfilename(initialdir="/", title="Select PDF File",
filetypes=(("PDF Files", "*.pdf"), ("All Files", "*.*")))
pdf_entry.delete(0, tk.END)
pdf_entry.insert(tk.END, pdf_file)
def select_docx_file():
docx_file = filedialog.asksaveasfilename(defaultextension=".docx", filetypes=[("Word Document", "*.docx")])
docx_entry.delete(0, tk.END)
docx_entry.insert(tk.END, docx_file)
def exit_program():
root.destroy()
# 创建主窗口
root = tk.Tk()
root.title("欢迎使用力江PDF转换器")
root.geometry("400x200")
# 创建输入框和按钮
pdf_label = tk.Label(root, text="PDF文件路径:")
pdf_label.place(x=20, y=13.5)
pdf_entry = tk.Entry(root)
pdf_entry.place(x=110, y=13.5)
pdf_button = tk.Button(root, text="选择文件", command=select_pdf_file, bg="#5AAD24")
pdf_button.place(x=265, y=10)
docx_label = tk.Label(root, text="DOCX文件路径:")
docx_label.place(x=10, y=53.5)
docx_entry = tk.Entry(root)
docx_entry.place(x=110, y=53.5)
docx_button = tk.Button(root, text="选择路径", command=select_docx_file, bg="#5EA4CE")
docx_button.place(x=265, y=50)
# 创建转换按钮
convert_button = tk.Button(root, text="开始转换", command=convert_pdf_to_docx, bg="#2AC48C")
convert_button.place(x=100, y=140)
# 创建退出按钮
exit_button = tk.Button(root, text="退出程序", command=exit_program, bg="#FE0000")
exit_button.place(x=230, y=140)
# 运行主循环
root.mainloop()
pdf文件转换成docx工具
于 2023-08-31 21:57:59 首次发布