So I am making a project which has numerous buttons and windows using Tkinter and I implemented tts using pyttsx3 module. Consider the following example:
import pyttsx3
from Tkinter import *
#configure text-to-speech
engine = pyttsx3.init()
def speak(text):
engine.setProperty("rate", 150)
engine.say(text)
engine.runAndWait()
root = Tk()
def submit():
top = Toplevel(root)
hello_world = Label(top, text = "Hello World")
hello_world.pack()
speak("Hello World")
click_me = Button(root, text = "Click Me", command = submit)
click_me.pack()
root.mainloop()
When the button is clicked the tts command will run first and the window will freeze until pyttsx3 finishes speaking and then only the window will load. And when there is a lot of text to speak this problem worsens.
What I want is that the tts command should execute after the window is loaded. How should I do this?