Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python gui tkinter蟒蛇3不工作始终停止_Python_Python 3.x_User Interface_Tkinter - Fatal编程技术网

Python gui tkinter蟒蛇3不工作始终停止

Python gui tkinter蟒蛇3不工作始终停止,python,python-3.x,user-interface,tkinter,Python,Python 3.x,User Interface,Tkinter,我的tkintergui代码是- 此代码显示我的gui没有响应 我在做语音助手这段代码是我从另一个网站上查到的,我试着在spyder或jupyter中运行,但无法运行,因为它显示没有响应 它根本没有把声音作为输入 我读了一些堆栈,但我不确定它是否会有帮助,所以需要一些关于代码错误的帮助 我读过一些文章说多线程可以用,我应该试试吗 from tkinter import* import pyttsx3 import speech_recognition as sr import pyaudio i

我的tkintergui代码是-

此代码显示我的gui没有响应

我在做语音助手这段代码是我从另一个网站上查到的,我试着在spyder或jupyter中运行,但无法运行,因为它显示没有响应 它根本没有把声音作为输入

我读了一些堆栈,但我不确定它是否会有帮助,所以需要一些关于代码错误的帮助

我读过一些文章说多线程可以用,我应该试试吗

from tkinter import*
import pyttsx3
import speech_recognition as sr
import pyaudio
import random
import time
from tkinter import messagebox
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
class Window(Frame):
    #defining our main window
    def __init__(self,master):
        self.master=master
        master.title("DREAM")
        A=Label(master,text="try saying *what can you do*")
        A.pack(side="top")
        Button(master,text="listen",width=100,relief="groove",command=self.Processo_r).pack(side="bottom")
    def Processo_r(self):
        speech=str(self.speech_recog())

        if speech=="What can you do":
            self.functions()  
    def speak(self,output):
        #initiating the speech engine
        engine = pyttsx3.init()
        #speaking the desired output 
        engine.say(output)
        engine.runAndWait()
    def functions(self):
        self.speak("here is a list of what i can do")
        messagebox.showinfo("DREAM functions", "1.Try saying 'Hi','Hello'" +
                            "\n2.Try asking 'What day is this?'" +
                            "\n3.Try asking 'What month is it?'" +
                            "\n4.Try asking 'What time is it?'" +
                            "\n5.You search in google by saying...'Search (or) Google <anything>'" +
                            "\n6.Play youtube by saying'YouTube... <video_name>'" +
                            "\n7.Search in Wikipedia by saying...'wikipedia...<anything>'" +
                            "\n8.To close say 'Bye' or 'Sleep' or 'See you later'")

    def speech_recog(self):
        #recognizer class
        r=sr.Recognizer()
        #Specifing the microphone to be activated
        mic = sr.Microphone(device_index=1)

        #listening to the user 
        with mic as s:
            audio = r.listen(s, timeout=5)
            r.adjust_for_ambient_noise(s)

        #Converting the audio to text  
        try:
            speech = r.recognize_google(audio)
            return speech

        except sr.UnknownValueError:
            #calling the text to speech function
            self.speak("please try again,couldnt identify")

        
        except sr.WaitTimeoutError as e:
            self.speak("please try again") 
    
    
root=Tk()
#instance of the class  
app=Window(root)
root.geometry("300x50")
#Runs the application until we close
root.mainloop()
从tkinter导入*
导入pyttsx3
将语音识别作为sr导入
导入pyaudio
随机输入
导入时间
从tkinter导入消息框
从selenium导入webdriver
从selenium.webdriver.common.keys导入密钥
类窗口(框架):
#定义我们的主窗口
定义初始(自我,主):
self.master=master
大师头衔(“梦想”)
A=标签(master,text=“试着说*你能做什么*”)
A.pack(side=“top”)
按钮(master,text=“listen”,width=100,relief=“groove”,command=self.Processo\u r).pack(side=“bottom”)
def处理程序(自身):
speech=str(self.speech\u recog())
如果speech==“你能做什么”:
self.functions()
def语音(自我,输出):
#启动语音引擎
engine=pyttsx3.init()
#说出期望的输出
发动机(输出)
engine.runAndWait()
def功能(自身):
self.speak(“这是我能做的事情的列表”)
showinfo(“梦想功能”,“1.试着说‘你好’,‘你好’”+
“\n2.试着问‘今天是星期几?’”+
“\n3.试着问‘现在是几月?’”+
“\n4.试着问‘现在几点了?’+
“\n5.你在谷歌搜索时说……‘搜索(或)谷歌’”+
“\n6.通过说‘youtube…’来播放youtube”+
“\n7.在Wikipedia中搜索时说…”“Wikipedia…””+
“\n8.要关闭,请说‘再见’或‘睡觉’或‘再见’”
def语音记录(自我):
#识别器类
r=高级识别器()
#指定要激活的麦克风
麦克风=高级麦克风(设备索引=1)
#倾听用户的声音
将话筒作为s:
音频=r。侦听(s,超时=5)
r、 调整环境噪声
#将音频转换为文本
尝试:
语音=r.recognize\u谷歌(音频)
回音
除sr.UnknownValue错误外:
#调用text-to-speech函数
self.speak(“请重试,无法识别”)
除高级WaitTimeOuter错误为e外:
self.speak(“请再试一次”)
root=Tk()
#类的实例
app=窗口(根)
根几何(“300x50”)
#运行应用程序直到关闭
root.mainloop()

为什么从
tkinter.Frame
继承而从不使用它?另外
r.listen(s,timeout=5)
正在阻止代码执行5秒。这意味着tkinter无法自我更新,这就是窗口挂起的原因。尝试在另一个线程中移动语音检测。