Python Forum
[Tkinter] Noob question:Using pyttsx3 with tkinter causes program to stop and close, any ideas?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Noob question:Using pyttsx3 with tkinter causes program to stop and close, any ideas?
#1
I installed the pyttsx3 libary to convert text to speech. And it works really great, until I want to use it in combination with tkinter. What happens that the program just closes, without any errors or what so ever. Weird enough it goes through the codes after engine.runAndWait(). I checked that by putting a print command after every line which shows up in the terminal, but I it 'ignores' the widgets that are supposed to be built up in the window. Any ideas? I'm using MacOs Mojave 10.14.6. with Python 3.8.5.

Here is the partial code with the problem, you can obviously ignore the print commands in between. I just left it so it's visible that it goes through the code, but only executing the print commands and ignoring the rest. Again, it works fine without tkinter, and the program also works fine when I don't use the pyttsx3 library. Here's the whole code: https://www.codepile.net/pile/rezzJ7ex and the JSON file that goes with it: https://www.codepile.net/pile/ePlYvbZM

else:
        random.shuffle(WORDS)
        for widget in window.winfo_children():
            widget.destroy()
        WORD = WORDS[0]
        tk.Label (window, image=photo1, bg="black") .grid(row=0, column=0)
        word = tk.Label (window, text = WORD, bg="black", fg="white", font="none 20 bold")
        word.grid(row=1, column=0)
        window.update()
        engine = pyttsx3.init()
        nl_voice_id = "com.apple.speech.synthesis.voice.ellen"
        engine.setProperty('rate', 100)
        engine.setProperty('voice', nl_voice_id)
        engine.say(WORD)
        engine.runAndWait()
        #del engine <this did not work
        print("after runAndWait")
        window.after(3000)
        print("after after")
        word['text'] = ''
        print("after text")
        window.update()
        print("after update")
        ANSWER = tk.Entry(window, width=20, bg="white")
        print("after entry")
        ANSWER.grid(row=2, column=0)
        print("after ANSWER")
        tk.Button(window, text="Check", width=6, command=lambda: check(ANSWER,WORD)) .grid(row=3, column=0)
        print("after button")
        WORDS.remove(WORD)
        print("after remove")
Reply
#2
Please show all code, or at least enough of it so that the issue can be replicated.
Reply
#3
Looks like this part in your code is blocking the mainloop in tkinter
Quote:engine.runAndWait()
you may need to use threading -> thread -> start, to separate the voice to text.
I would create a function which starts the voice to text. threading module
Reply
#4
(Nov-14-2020, 01:56 AM)joe_momma Wrote: Looks like this part in your code is blocking the mainloop in tkinter
Quote:engine.runAndWait()
you may need to use threading -> thread -> start, to separate the voice to text.
I would create a function which starts the voice to text. threading module

Thanks! Just to make sure.. All the print commands after
Quote:engine.runAndWait()
are executed in the terminal. I also googled threading but I don't know how to use it the functions of threading. So, while threading.TIMEOUT_MAX seems like an option, I don't have an idea how to implement it (just started python a few weeks ago..) Do you have suggestions?
Reply
#5
(Nov-14-2020, 01:33 AM)Larz60+ Wrote: Please show all code, or at least enough of it so that the issue can be replicated.

Hi thanks, I've added the links to codepile containing the whole code and the JSON file, so I don't clutter the post. It's also my first post here. Would you recommend to paste the whole code here? Do you maybe also have suggestions for the question? Just started python a few weeks ago and I'm really stuck. Thanks.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python tkinter question tablet Nick_tkinter 8 1,124 Mar-04-2021, 10:44 PM
Last Post: Larz60+
  tkinter slider question Nick_tkinter 1 484 Feb-22-2021, 01:31 PM
Last Post: deanhystad
  How to stop time counter in Tkinter LoneStar 1 1,133 Sep-11-2020, 08:56 PM
Last Post: Yoriz
  question on tkinter canvas PhotoImage gr3yali3n 1 597 Sep-05-2020, 12:18 PM
Last Post: Larz60+
  [Tkinter] How to close all windows when exit program scratchmyhead 3 2,329 May-17-2020, 08:19 AM
Last Post: menator01
  Tkinter parameter question DPaul 2 726 Mar-14-2020, 09:35 AM
Last Post: DPaul
  How to close one of the windows in Tkinter scratchmyhead 3 1,964 Dec-21-2019, 06:48 PM
Last Post: pashaliski
  tkInter and Pillow don't display any images in GUIs - program gives errors instead SomeRandomGuy 9 4,637 Oct-29-2019, 02:57 PM
Last Post: SomeRandomGuy
  Newbie question with Tkinter Entry mariolopes 2 910 Oct-12-2019, 11:02 PM
Last Post: Larz60+
  Stop Watch star/stop problem macellan85 1 999 Jun-12-2019, 06:04 PM
Last Post: woooee

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020