4

I installed Anaconda in my MacBookPro (OSX 10.11.4 El Capitan) and try to run the following program of Python3.5.1 using Spyder2;

from tkinter import *
import sys
win = Tk()
button = Button(win, text='Push this Button!', command=exit)
button.pack()
mainloop()

However, Spyder2 tells me "from tkinter import * used; unable to detect undefined names", I cannot run it under Spyder2. However, after saving it with the name of "Sample.py" and run it in the Terminal, I can run it successfully. I suppose this error might be caused unresolved error in linker. Can you help me? I also encountered this problem when I installed Anaconda in Windows10.

Thank you Bryan. I tried the following code in Spyder2;

import tkinter as tk
import sys
win=tk.Tk()
button=tk.Button(win,text="Goodbye",command=exit)
button.pack()
tk.mainloop()

Then, it worked. However, still I do not understand why the original one did not work under Spyder 2, while it nicely worked under Bash.

Dr_Radialist
  • 41
  • 1
  • 1
  • 4
  • 3
    Why are you using `from tkinter import *`? wildcard imports shouldn't be used. Use a normal import (eg: `import tkinter` or `import tkinter as tk`). – Bryan Oakley Apr 29 '16 at 11:23
  • Here is a discussion on wildcard imports https://stackoverflow.com/questions/3615125/should-wildcard-import-be-avoided – Pratap Muthukrishnan Dec 16 '18 at 05:01

0 Answers0