25行python代码实现文本朗读器

雨啸青锋 发布于 2020-04-20 628 次阅读


 

from tkinter import *
import pyttsx3
from _thread import start_new_thread
win = Tk()
win.title("语言朗读器")
sd = win.winfo_screenwidth()   
sh = win.winfo_screenheight()  
wd = 800
wh = 500
x = (sd-wd) / 2  
y = (sh-wh) / 2 
win.geometry("%dx%d+%d+%d" %(wd,wh,x,y))
def Voice(text):
    voice = pyttsx3.init()
    voice.say(text)
    voice.runAndWait()
textwin = Frame(win)
textwin.place(relx = 0,rely = 0,relheight = 0.85,relwidth = 1)
text = Text(textwin,font = ("楷体",15))
text.pack(fill = BOTH,expand  = YES)
buttonwin = Frame(win)
buttonwin.place(relx = 0,rely = 0.85,relheight = 0.1,relwidth = 1)
ok = Button(buttonwin,text = "转语言",height = 8,command = lambda :start_new_thread(Voice,(text.get("0.0",END),)))
ok.pack()
mainloop()

 

嘿,大家好,小名尧尧,网名雨啸青锋,00后的小站主,某校高中生
最后更新于 2020-04-20