0

I'm using the pyttsx3 module. When I run the program after the voice finishes speaking, the window closes automatically. I've been searching the internet, but I haven't found an answer yet. Some people are having this problem as well, however, they didn't get a proper solution.

This is the code:

from tkinter import *
import pyttsx3


root = Tk()
root.title("Holi")
root.geometry("500x400")


def talk():
    engine = pyttsx3.init()
    engine.say(my_entry.get())
    engine.runAndWait()

    my_entry.delete(0, END)


my_entry = Entry(root, font=("Helvetica", 28))
my_entry.pack(pady=20)


my_button = Button(root, text='Speak', command=talk)
my_button.pack(pady=20)
root.mainloop()

It seems to have to do something with runAndWait() and the mainloop(). I also tried a solution using the threading module but it didn't work.

David 04
  • 37
  • 5
  • Out of curiosity, how did you implement threading? It should be fairly straightforward to run `talk()` as the target of a separate thread...but I know tkinter is often fussy about threading. – JRiggles Dec 01 '22 at 18:21

0 Answers0