欢迎光临散文网 会员登陆 & 注册

修改傻瓜阅读软件,显示读书内容(I)

2020-03-29 11:46 作者:一心想当网红的李老师  | 我要投稿

修改了上次的傻瓜阅读软件。

import importlib,sys

importlib.reload(sys)


import tkinter

from tkinter.filedialog import askopenfilename

from docx import Document

from docx.shared import Inches

import pyttsx3

from tkinter import *

from tkinter import ttk

import os



l=[]

def openfile():

    global file_path

    file_path=askopenfilename()   

    if os.path.splitext(str(file_path))[1]=='.txt':  ###对于TXT文件的处理

        f=open(file_path,encoding='utf-8')

        fread=f.read()

        f=str(fread)

        text.insert(END,f)

        engine=pyttsx3.init()

        engine.say(f)

        engine.runAndWait()

    elif os.path.splitext(str(file_path))[1]=='.docx': ###对于WORD文件处理

        f=Document(file_path)

        for para in f.paragraphs:

            l.append(para.text)

        text.insert(END,str(l))

        engine=pyttsx3.init()

        engine.say(str(l))

        engine.runAndWait()



if __name__=='__main__':

    root=Tk()

    root.title('读书软件')

    root.geometry("720x480")

    root.configure(bg="white")

    Button1=tkinter.Button(root, text ="选择文件", command = openfile)

    Button1.grid(row=0,column=0,padx=20,pady=20)

    text=tkinter.Text(root,bg="yellow")

    text.grid(row=0,column=1,padx=20,pady=20)   

    root.mainloop()


修改傻瓜阅读软件,显示读书内容(I)的评论 (共 条)

分享到微博请遵守国家法律