1

Hello and thanks for looking at this,

When I try to import tkinter it says unresolved import

ImportError: No module named tkinter

There was some kind of error when I installed python originally

Here are the paths:

Output:

/Library/Python/2.7/site-packages
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-     scriptpackages
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip
/Users/wes/Desktop/UM/Python/guiTest
/Users/wes/Desktop/UM/Python/guiTest/testgui

Thanks -Wes

martineau
  • 119,623
  • 25
  • 170
  • 301
user2395350
  • 11
  • 1
  • 2
  • 1
    In Python 2.7, the module should be called `Tkinter`, with a capital T. Could you try `import Tkinter`? – DSM May 17 '13 at 20:33
  • See if there's a `/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py` -- again note the capital `T`. – martineau May 17 '13 at 20:44
  • I have Tkinter.pyo and Tkinter.pyc but no Tkinter.py – user2395350 May 17 '13 at 20:53
  • More info: I am trying to use the MessageBox. If I comment every thing else out the first import "from Tkinter import *" seems to be ok – user2395350 May 17 '13 at 21:08
  • If the error is `No module named tkinter` (with lowercase T) then the problem is that you are trying to import Tkinter with the name of Python 3. Could you post the code with all the import statements? – A. Rodas May 17 '13 at 21:27
  • from tkinter import * import tkinter.messagebox def beenClicked(): radioValue = relStatus.get() tkinter.messagebox.showinfo("You clicked", radioValue) return def changeLabel(): name = "Thanks for the click " + yourName.get() labelText.set(name) yourName.delete(0, END) yourName.insert(0, "My name is Derek") return app = Tk() app.title("GUI Example") app.geometry('450×300+200+200') – user2395350 May 17 '13 at 21:34
  • sorry I forgot "return" sends the comment. This code is from new think tank and it works when Derek does it. – user2395350 May 17 '13 at 21:36
  • Possible duplicate of [Which tkinter modules were renamed in Python 3?](https://stackoverflow.com/questions/673174/which-tkinter-modules-were-renamed-in-python-3) – Stevoisiak Mar 30 '18 at 20:08

2 Answers2

1

You are importing tkinter with lowercase T. The code you posted in your comment is for Python 3.X, and the import statements are correct if you have that version too, but since you are using Python 2.7, the names for the modules are Tkinter and tkMessageBox (instead of tkinter and tkinter.messagebox).

A. Rodas
  • 20,171
  • 8
  • 62
  • 72
  • Thank you for your post. Unfortunately it is still giving me the "unresolved import" compile time message while using Tkinter and tkMessageBox – user2395350 May 18 '13 at 03:33
  • @user2395350 Which OS are you using? Can you check if there exists `_tkinter` in the `libs` (with s) folder? – A. Rodas May 18 '13 at 03:44
  • I am using osx, It allows me to import _tkinter but I am not sure what libs (with s) means. I don't see a folder like that. – user2395350 May 18 '13 at 14:52
  • _tkinter is a module written in C that Tkinter needs to work. All this modules are in the libs folder (usually in the same directory as Lib). If you had a problem during the installation, I suggest you to install Python 3 directly and take a look also to http://www.python.org/getit/mac/tcltk/ – A. Rodas May 18 '13 at 15:38
0

Finally figured it out! Thanks. My mac comes with python 2.7 in system/Library and auto config defalts to this however this is not the version that I downloaded and updated.The version that I downloaded went into Library not System and the Capital T in Tkinter was important as you said for 2.7 Thanks for your help