2

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 ?

0

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

sudo apt-get install python-tk
  • I already tried apt-get install python-tk, but it still give the same error – Zeiad Badawy Sep 9 '17 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.

  • I use python2.7, so no need to install python3-tk. – Zeiad Badawy Sep 9 '17 at 23:50
  • @ZeiadBadawy Again, if there's no good reason, use Python 3. – Timo Sep 10 '17 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. – Zeiad Badawy Sep 10 '17 at 16:41
  • Are the following packages installed? sudo apt-get install tk8.6 libtk8.6 tcl8.6 libtcl8.6 – Timo Sep 12 '17 at 7:35

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.