0

I am new to Python. I downloaded Spyder 2.3.1 and am running Python 2.7 on my Mac. I tried this sample program:

from Tkinter import *
root = Tk()

w = Label(root, text="Hello, world!")
w.pack()

root.mainloop()

When I run, I get the error message:

NameError: name 'Tk' is not defined

If I look in the file Tkinter.py, it has the following lines of code:

from Tkinter import *
root = Tk()

w = Label(root, text="Hello, world!")
w.pack()

root.mainloop()

Looks like an infinite loop, but what it is complaining about is "Tk" saying "name not defined". Any help would be greatly appreciated.


p.s. I tried python -m idlelib.idle in a Terminal window and got the error NameError: name 'Tk' is not defined

anon582847382
  • 19,907
  • 5
  • 54
  • 57
user3229570
  • 853
  • 2
  • 10
  • 23

1 Answers1

1

The filename Tkinter.py prevent the import of the standard library module Tkinter.

Rename the file with different name. Also you shouold remove Tkinter.pyc if there it is.

falsetru
  • 357,413
  • 63
  • 732
  • 636
  • one more question. I see files open in Spyder that are in the folder path /Users/Ameade/.spyder2/My_Amazing_Script.py - but I don't see a folder called ".spyder2" anywhere. Can you tell me where this is? – user3229570 Oct 26 '14 at 15:30
  • @user3229570, In Unix sytem, the filename starts with a dot `.` is hidden. You can see the file with command likes `ls -a`. If you don't use command line, check your file browser's option to show hidden files/directories. – falsetru Oct 26 '14 at 15:45
  • Thanks. I was able to navigate there using the Go menu. I think I will just move these files to another folder. – user3229570 Oct 26 '14 at 15:47