傻瓜读书软件升级(txt, word都可以)
版本是python3.7
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import importlib,sys
importlib.reload(sys)
import tkinter
from tkinter.filedialog import askopenfilename
from docx import Document
from docx.shared import Inches
import pyttsx3
l=[]
def openfilewd():
file_path=askopenfilename()
f=Document(file_path)
for para in f.paragraphs:
l.append(para.text)
engine=pyttsx3.init()
engine.say(str(l))
engine.runAndWait()
def openfiletxt():
file_path=askopenfilename()
f=open(file_path,encoding='utf-8')
fread=f.read()
f=str(fread)
engine=pyttsx3.init()
engine.say(f)
engine.runAndWait()
top=tkinter.Tk()
Button1=tkinter.Button(top, text ="选择txt文件", command = openfiletxt)
Button2=tkinter.Button(top, text ="选择word文件", command = openfilewd)
Button1.pack()
Button2.pack()
top.mainloop()
其实就是把两个程序并在了一起。做了两个选择图标的界面。
后面可以在程序内部分析文件的格式,然后选择处理方式。