Click here to Skip to main content
15,040,003 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
so, recently I made a virtual assistant (Friday) successfully on windows. But the cli was boring so I tried to make it in gui but was having some error ->
Traceback (most recent call last):
  File "e:\friday_\test.py", line 13, in <module>
    speak("hi")
  File "e:\friday_\test.py", line 9, in speak
    text = tk.Label('Computer: ' + audio)
  File "e:\python_important\lib\tkinter\__init__.py", line 3144, in __init__
    Widget.__init__(self, master, 'label', cnf, kw)
  File "e:\python_important\lib\tkinter\__init__.py", line 2562, in __init__
    BaseWidget._setup(self, master, cnf)
  File "e:\python_important\lib\tkinter\__init__.py", line 2531, in _setup
    self.tk = master.tk
AttributeError: 'str' object has no attribute 'tk'


Here is the actual code ->


import pyttsx3
import tkinter as tk

engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)
tk.Tk()
def speak(audio):
    text = tk.Label('Computer: ' + audio)
    engine.say(audio)
    engine.runAndWait()
    text.pack()
speak("hi")
tk.mainloop()


So, what can be the solution to this? any help would be appreciated

What I have tried:

I have tried searching on google but can't find it.
Posted
Updated 19-Dec-20 17:05pm

1 solution

Your call to Label is incorrect. The first parameter needs to be a reference to the Window (I think). See Labels in Tkinter (GUI Programming) - Python Tutorial[^].
   
Comments
Krrishdhaneja 19-Dec-20 23:08pm
   
Ya, after that i corrected it and it was fine but i was getting the gui response when program ended because
tk.mainloop()
was at end but if i put it in between the code then the code didn’t get executed. So what can i do with this?
Krrishdhaneja 19-Dec-20 23:10pm
   
Actually in label in forgot to put
text=

@Richard MacCutchan

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900