傻瓜讀書軟件升級(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()
其實(shí)就是把兩個(gè)程序并在了一起。做了兩個(gè)選擇圖標(biāo)的界面。
后面可以在程序內(nèi)部分析文件的格式,然后選擇處理方式。