'AttributeError: 'str' object has no attribute 'tk' when click button [duplicate]

Here is my code:


window = tk.Tk()


version = tk.Label(text="hi",
                   fg="orange",
                   bg="black",
                   width=20,
                   height=10,
                   )
version.pack()
enter = tk.Button(text="START",fg="blue",width=20,height=7)
enter.pack()

def click(event):
    version.forget()
    enter.forget()
    name = tk.Label("name")
    entry = tk.Entry()
    name.pack()
    entry.pack()


enter.bind("<Button-1>", click)



window.mainloop()

As you can see, I wanted to make a Label and an Entry appear once the START button is clicked.

When I click the button, though, it returns this error:

Exception in Tkinter callback
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/tkinter/__init__.py", line 1892, in __call__
    return self.func(*args)
  File "/Users/name/Desktop/project/gui/main.py", line 19, in click
    name = tk.Label("name")
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/tkinter/__init__.py", line 3148, in __init__
    Widget.__init__(self, master, 'label', cnf, kw)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/tkinter/__init__.py", line 2566, in __init__
    BaseWidget._setup(self, master, cnf)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/tkinter/__init__.py", line 2535, in _setup
    self.tk = master.tk
AttributeError: 'str' object has no attribute 'tk'

I don't know what is happening here.



Solution 1:[1]

Per the error statement, the origin of the problem is this line:

File "/Users/name/Desktop/project/gui/main.py", line 19, in click
    name = tk.Label("name")

The first expected argument of a Label is the "master", or parent window.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mandias