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
  Beginner question re: Tkinter geometry return2sender 3 905 Jun-19-2023, 06:19 PM
Last Post: deanhystad
  Tkinter GUI question texan1836 3 1,822 Apr-13-2023, 03:12 AM
Last Post: deanhystad
  simple tkinter question function call not opening image gr3yali3n 5 3,303 Aug-02-2022, 09:13 PM
Last Post: woooee
  'Your first program' type question, be kind davediamond 0 1,045 Apr-11-2022, 08:12 PM
Last Post: davediamond
  [Tkinter] question for a tkinter dialog box RobertAlvarez424 2 2,203 Aug-25-2021, 03:08 PM
Last Post: RobertAlvarez424
  Python tkinter question tablet Nick_tkinter 8 4,924 Mar-04-2021, 10:44 PM
Last Post: Larz60+
  tkinter slider question Nick_tkinter 1 2,433 Feb-22-2021, 01:31 PM
Last Post: deanhystad
  How to stop time counter in Tkinter LoneStar 1 4,294 Sep-11-2020, 08:56 PM
Last Post: Yoriz
  question on tkinter canvas PhotoImage gr3yali3n 1 2,105 Sep-05-2020, 12:18 PM
Last Post: Larz60+
  [Tkinter] How to close all windows when exit program scratchmyhead 3 6,311 May-17-2020, 08:19 AM
Last Post: menator01

Forum Jump:

User Panel Messages

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