站长高三,更新会慢些。

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

经典语录 雨啸青锋 5个月前 (04-20) 97次浏览 0个评论 扫描二维码

 

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()

 

喜欢 (0)
[]
分享 (0)
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址