为什么我的tkinter代码在调用函数[python3]后停止运行?

时间:2019-03-09 15:51:07

标签: python python-3.x tkinter

我有一些tkinter代码,说明用户输入的内容,但是仅被调用一次后关闭?如果有人知道如何解决此问题并使它继续运行,直到按下“退出”按钮。

代码如下:

import speech_recognition as sr
import pyttsx3
from colorama import init
from colorama import Fore, Back, Style
import tkinter as tk

init()
again = "yes"
r = sr.Recognizer()


root = tk.Tk()
root.title("Textspeaker")
Entrys = tk.StringVar()
LabelEntrys = tk.Label(text="What do you want to be said?").grid(row = 0, column = 0, padx = 0, pady = 10)
EntryEntrys = tk.Entry(textvariable = Entrys).grid(row = 0, column = 1)


def Textspeaker() :
    # question = input("type something to be read: ")
    question = Entrys.get()
    engine = pyttsx3.init()
    engine.setProperty('rate', 160)

    engine.say(str(question))
    engine.runAndWait()
    root.update()

def stopthecode():
    root.destroy()
Button= tk.Button(text = 'Execute', command = Textspeaker, fg='red', font='Helvetica 18 bold').grid(row = 1, column = 1)
Button2= tk.Button(text = 'Quit', command = stopthecode, fg='red', font='Helvetica 18 bold').grid(row = 2, column = 1)
root.mainloop()

0 个答案:

没有答案