作者: | 来源:互联网 | 2023-10-10 15:38
1.安装pdf2docx
打开python安装目录,地址栏输入cmd回车,输入pip install pdf2docx回车
2.编辑代码
打开IDLE ,菜单栏file->new file,输入代码,ctrl+S保存文件demo.py,F5运行。以下是代码。
from pdf2docx import Converter
import tkinter
import time
import threading
from tkinter import filedialog
event = threading.Event()
Once=0
#PDF文件选择
def pdfchoose():
Filepath = filedialog.askopenfilename()
entry1.insert(0,Filepath)
#doc路径选择
def docchoose():
Folderpath = filedialog.askdirectory()
entry2.insert(0,Folderpath)
def docchange():
if s3.get():
docname=s3.get()+'.doc'
entry3.delete(0,s3.get())
entry3.insert(0,docname)
#PDF转word文档
def pdftodoc():
docx_file='' # convert pdf to docx
if not s1.get():
print('请选择PDF文件')
s3name=''
s2name=''
if not s3.get():
s3name='doc.doc'
else:
s3name=s3.get()
if not s2.get():
docx_file=s1.get().replace('pdf','doc')
else:
docx_file=s2.get()+'//'+s3name
pdf_file = s1.get()
cv = Converter(pdf_file)
cv.convert(docx_file, start=0, end=None)
cv.close()
def main():
try:
print(s1.get(),s2.get())
for i in range(0, 30):
mpb["value"] = i
text.see(tkinter.END) # 一直查看文本的最后位置~
text.insert('end', "验证不通过,请查看!" + str(i) + "\r\n")
# scale.config(mode='determinate', maximum=11.0, value=i)
text.update() # 一直更新输出
print(i)
time.sleep(0.1)
event.wait()
window.update()
text.insert('end', "程序运行完成!" + "\r\n")
text.update()
text.see(tkinter.END)
print("验证不通过!")
pass
except:
pass
def thread():
# while True:
main()
window = tkinter.Tk()
window.title('PDF转DOC')
#编辑框
l1=tkinter.Label(text="PDF文件路径")
l1.grid(row=0,column=0)s1 = tkinter.StringVar()
entry1 = tkinter.Entry(window, textvariable=s1,bd=5,word输出文件路径")
l2.grid(row=1,column=0)
s2 = tkinter.StringVar()
entry2 = tkinter.Entry(window, textvariable=s2,bd=5,word文件名")
l3.grid(row=2,column=0)
s3 = tkinter.StringVar()
entry3 = tkinter.Entry(window, textvariable=s3,bd=5,focusout",vcmd=docchange)
entry3.grid(row=2,column=1)
#按钮名称,函数,位置
button1=tkinter.Button(window,text='PDF 路 径',command=pdfchoose)
button1.grid(row=0,column=2)
button2=tkinter.Button(window,text='DOC 路径',command=docchoose)
button2.grid(row=1,column=2)
button3=tkinter.Button(window,text='转 换',command=pdftodoc)
button3.grid(row=2,column=2)
3.打包exe
打开python安装目录,地址栏输入cmd回车,输入pip install PyInstaller回车
打开demo.py安装目录,地址栏输入cmd回车,输入pyinstaller -F demo.py,生成文件在dist目录下
https://download.csdn.net/download/qq_44233281/20371061