3

When I try the following code :

import Tkinter
Tkinter._test()

I get the following error :

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 3835, in _test
    root = Tk()
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1818, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: Can't find a usable tk.tcl in the following directories: 
/usr/local/lib/tcl8.6/tk8.6 /usr/local/lib/tk8.6 /usr/lib/tk8.6 /usr/lib/tk8.6 /lib/tk8.6 /usr/library



This probably means that tk wasn't installed properly.

I tried to reinstall Tkinter, but it still give the same error.

Can I have help please ?

2 Answers 2

0

Install python-tk and I think you will solve your problems.

sudo apt-get install python-tk
1
  • I already tried apt-get install python-tk, but it still give the same error Sep 9, 2017 at 2:11
0

Tkinter has a different name in Python 2 and 3.

  • Python 2: import Tkinter
  • Python 3: import tkinter

Unless you have a very good reason, use Python 3. Make sure tkinter is installed by running sudo apt-get install python3-tk and use the python3 command in the terminal.

4
  • I use python2.7, so no need to install python3-tk. Sep 9, 2017 at 23:50
  • @ZeiadBadawy Again, if there's no good reason, use Python 3.
    – Timo
    Sep 10, 2017 at 7:57
  • I just tried to use Python 3 and it gives the same error. The problem is not with the tkinter module, it is with tk like it is shown in the last line of my error : This probably means that tk wasn't installed properly. I don't know what I did with tk, but I should fix the problem because I can't use my GUI programs and the python idle. Sep 10, 2017 at 16:41
  • 1
    Are the following packages installed? sudo apt-get install tk8.6 libtk8.6 tcl8.6 libtcl8.6
    – Timo
    Sep 12, 2017 at 7:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .