0

The program:

from tkinter import *
root = Tk()
canvas = Canvas(root)
canvas.pack()
root.mainloop()

error for this program:

c:/Users/ADMIN/Desktop/python/tkinter.py
Traceback (most recent call last):
  File "c:\Users\ADMIN\Desktop\python\tkinter.py", line 1, in <module>     
    from tkinter import *
  File "c:\Users\ADMIN\Desktop\python\tkinter.py", line 3, in <module>     
    root = Tk()
NameError: name 'Tk' is not defined

is the problem I am still facing in my computer. please help me to rectify this error

TheLizzard
  • 7,248
  • 2
  • 11
  • 31
  • 2
    Don't name your file `tkinter.py`. Name it something like `GUI.py` – TheLizzard Jul 05 '21 at 09:08
  • In other words: you're importing your own file. – Matthias Jul 05 '21 at 09:12
  • You have named your file ```tkinter.py```. instead of fetching from the real tkinter folder, it is trying to fetch ```Tk``` from your file –  Jul 05 '21 at 09:12
  • 2
    Does this answer your question? [Python Tkinter Tk is not defined](https://stackoverflow.com/questions/42616501/python-tkinter-tk-is-not-defined) – acw1668 Jul 05 '21 at 09:40

0 Answers0