Click here to Skip to main content
15,877,754 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_\", line 13, in <module>
  File "e:\friday_\", line 9, in speak
    text = tk.Label('Computer: ' + audio)
  File "e:\python_important\lib\tkinter\", line 3144, in __init__
    Widget.__init__(self, master, 'label', cnf, kw)
  File "e:\python_important\lib\tkinter\", line 2562, in __init__
    BaseWidget._setup(self, master, cnf)
  File "e:\python_important\lib\tkinter\", line 2531, in _setup =
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)
def speak(audio):
    text = tk.Label('Computer: ' + audio)

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.
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[^].
Share this answer
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
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

@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