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