1
我试图建立一个Tkinter的GUI有点像个人助理,但我已经倒在拳头障碍:(当我更新GUI和侦听speech_recognition,它会冻结并说没有响应!我明白,我需要使用多线程但我被困在如何使用它!python多线程与tkinter
这里是我的代码和我在使用多线程失败的尝试。
import tkinter as tk
from subprocess import call as say
import winsound
import speech_recognition as sr
import threading
def cbc(tex):
return lambda : callback(tex)
def callback(tex):
button = "Listen"
tex.insert(tk.END, button)
tex.see(tk.END)# Scroll if necessary
def listen(tex):
def callback(tex):
g = ("Say,,your,,command,,after,,the,,beep")
say('espeak '+ g, shell = True)
winsound.Beep(1000,500)
ltext = 'listening...'
tex.insert(tk.END, ltext)
r = sr.Recognizer()
with sr.Microphone() as source:
damand = r.listen(source)
damandtxt = (recognizer_google(damand))
tex.insert(tk5.END, damandtxt)
tex.see(tk.END)
t3 = threading.Thread(target = callback(tex))
t3.daemon = True
t3.start()
top = tk.Tk()
tex = tk.Text(master=top)
tex.pack(side=tk.RIGHT)
bop = tk.Frame()
bop.pack(side=tk.LEFT)
tk.Button(bop, text='Listen', command=lambda: listen(tex)).pack()
tk.Button(bop, text='Exit', command=top.destroy).pack()
top.mainloop()
我只需要知道如何正确使用它。请
ps我读过的所有文件,一切都在多线程,但它只是不工作:“(
预先感谢您:)