Python+GUI将pdf转换成为word

这是一个使用Python的tkinter库创建的简单GUI应用,它允许用户选择PDF文件并将其转换为Word文档。应用依赖于pdf2docx库来执行转换,并让用户指定输出文件的保存路径。
import tkinter as tk
from tkinter import filedialog
import os
from pdf2docx import parse

def select_pdf():
    global pdf_path
    pdf_path = filedialog.askopenfilename(title="选择 PDF", filetypes=[("PDF Files", "*.pdf")])
    pdf_label.config(text=f"Selected PDF: {os.path.basename(pdf_path)}")

def select_output():
    global output_path
    output_path = filedialog.asksaveasfilename(title="Select Output", defaultextension=".docx", filetypes=[("Word Files", "*.docx")])
    output_label.config(text=f"Output Path: {output_path}")

def convert_pdf():
    parse(pdf_path, output_path)
    success_label.config(text="转换成功!!!")

root = tk.Tk()
root.title("PDF转换成Word version1-By HuangAnthony 有问题请联系445218346@qq.com")
root.geometry("400x300")

pdf_label = tk.Label(root, text="暂未选择pdf")
pdf_label.pack()

pdf_button = tk.Button(root, text="请选择要转换的PDF", command=select_pdf)
pdf_button.pack()

output_label = tk.Label(root, text="务必要为生成的文件命名新的名字")
output_label.pack()

output_button = tk.Button(root, text="请选择要保存的路径", command=select_output)
output_button.pack()

convert_button = tk.Button(root, text="转换", command=convert_pdf)
convert_button.pack()

success_label = tk.Label(root, text="")
success_label.pack()

root.mainloop()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值