5

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
  • 51
  • 1
  • 1
  • 4
  • 5
    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
  • 1
    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
  • 1
    Does this answer your question? [Spyder IDE complaining about unable to detect undefined names](https://stackoverflow.com/questions/50439309/spyder-ide-complaining-about-unable-to-detect-undefined-names) – aaron Jan 31 '23 at 13:56

1 Answers1

0

I got the same message. Like this I suppressed the wildcard. There is no error now. But keeps on not showing the form.

import PyQt5

from PyQt5 import QtWidgets

from PyQt5 import QtGui

from PyQt5 import QtCore

from PyQt5.QtWidgets import QMainWindow

from PyQt5.QtWidgets import QApplication
lepsch
  • 8,927
  • 5
  • 24
  • 44