4

When I try to install tkinter using this command:

sudo apt-get install python-tk

I get this message meaning it is already installed:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
python-tk is already the newest version.
The following package was automatically installed and is no longer required:
  libjpeg62
Use 'apt-get autoremove' to remove it.
0 upgraded, 0 newly installed, 0 to remove and 9 not upgraded.

When I want to import it, I get this message error:

begueradj@begueradj-darwin:~/begueradj# python
Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from tkinter import *
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named tkinter
>>> 

How to fix this ?

2

To use Tkinter, all you need to do is to import one module:

import Tkinter

Or, more often:

from Tkinter import *

So just change your import line to import Tkinter for example:

$ python
Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import Tkinter
>>> Tkinter.TkVersion
8.6
>>> 

Source: https://docs.python.org/2/library/tkinter.html#tkinter-modules

11

If you are running python ver 3.x.x you should install tkinter for python3

sudo apt-get install python3-tk

That worked for me.

  • 1
    As you'd note from reading the question, the OP is using python 2.7.6. – Guss Dec 24 '15 at 19:01
2

Note Tkinter has been renamed to tkinter in Python 3. (source:https://stackoverflow.com/questions/25905540/importerror-no-module-named-tkinter). So in your codes, use import tkinter instead of import Tkinter. Also, in the codes, where there is Tkinter, use tkinter small letter instead.

  • as you'd note from reading the question, the OP is using python 2.7.6 – Guss Dec 24 '15 at 19:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy