#—*—coding:utf-8-*-
#Author:yizipu
#Time:2021/7/7 21:16
#file:懒人听书pc端.py
import pyttsx3
import tkinter as tk
import tkinter.filedialog as tkf
from tkinter import messagebox
window=tk.Tk()
window.title('听力软件')
window.geometry('700x480')
window['background']='green'
def select():
global book_text
path=tkf.askopenfilename()
if not path:
messagebox.showinfo('出错了','请选择txt文件')
else:
with open(path, 'r', encoding='utf-8')as fp:
book_text = fp.read()
text.insert('end',book_text)
def start():
#if not text.get(1.0,2.0):
#messagebox.showinfo('出错了','请选择txt文件')
#else:#解决当未选择文本时,点击开始按钮的情况,生成程序时,点击按钮不变化
repeater=pyttsx3.init()
repeater.say(text.get(1.0,'end'))
repeater.runAndWait()
repeater.stop()
text=tk.Text(window)
text.place(x=20,y=20,width=600,height=400)
button1=tk.Button(window,text='选择书籍',command=select)
button1.place(x=50,y=430,width=100,height=40)
button2=tk.Button(window,text='开始听书',command=start2)
button2.place(x=250,y=430,width=100,height=40)
button3=tk.Button(window,text='退去',command=window.quit)
button3.place(x=450,y=430,width=100,height=40)
window.mainloop()
//该程序有待进一步优化
|