3

I receive following Traceback:

Traceback (most recent call last):
  File "tkinter_basic_frame.py", line 4, in <module>
    from Tkinter import Tk, Frame, BOTH
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 42, in 
    raise ImportError, str(msg) + ', please install the python-tk package'
ImportError: No module named _tkinter, please install the python-tk package

This is the demoscript I'm trying to run:

#!/usr/bin/python
# -*- coding: utf-8 -*-

from Tkinter import Tk, Frame, BOTH


class Example(Frame):

    def __init__(self, parent):
        Frame.__init__(self, parent, background="white")   

        self.parent = parent

        self.initUI()

    def initUI(self):

        self.parent.title("Simple")
        self.pack(fill=BOTH, expand=1)


def main():

    root = Tk()
    root.geometry("250x150+300+300")
    app = Example(root)
    root.mainloop()  


if __name__ == '__main__':
    main()  

From my knowledge Tkinter should be included in Python 2.7. Why do I receive the traceback? Doesn't ubuntu contain the standard-python-distribution?

This is solved. I had to install it manually in synaptic (got the hint in the meantime from another forum), see here:

enter image description here

Wikipedia says: "Tkinter is a Python binding to the Tk GUI toolkit. It is the standard Python interface to the Tk GUI toolkit1 and is Python's de facto standard GUI,2 and is included with the standard Windows and Mac OS X install of Python." - Not good, that it isn't included in Ubuntu as well.

Tkinter on Wikipedia

0
1

Just install the tkinter

sudo apt-get install python-tk

or if you choose python3

sudo apt-get install python3-tk

http://tkinter.unpythonic.net/wiki/How_to_install_Tkinter

1
  • You should format Terminal commands as code.
    – Xweque
    Feb 21 '15 at 18:27
0

Do what the script says:

ImportError: No module named _tkinter, please install the python-tk package

Tkinter is not part of standard python on Linux based OS'es. It's a widget extension for GUI Creation. From the Python Wiki:

Tkinter is Python's de-facto standard GUI (Graphical User Interface) package. It is a thin object-oriented layer on top of Tcl/Tk.

On top of usually denotes an extra package. Anyhow, here is a link to the python-tk package.

7
  • @E Carter Young "Tkinter is a Python binding to the Tk GUI toolkit. It is the standard Python interface to the Tk GUI toolkit[1] and is Python's de facto standard GUI,[2] and is included with the standard Windows and Mac OS X install of Python." See: en.wikipedia.org/wiki/Tkinter
    – empedokles
    Aug 21 '14 at 21:37
  • Ubuntu is neither Windows nor OSX, therefore the need to install the package. See Bolded Text
    – eyoung100
    Aug 21 '14 at 21:44
  • @E Carter Young Well, of course nobody forces Ubuntu to care about Python conventions and its official distributions. In the German Lema it says that these Tkinter GUIs work under Linux though..
    – empedokles
    Aug 21 '14 at 21:48
  • Unfortunately, Internet writers have a tendency to skip over some of the nuances regarding requirements. Some distros include tkinter as a part of Python, some resolve it as a dependency, and some forget it all together. Gentoo also leaves it as an extra package.
    – eyoung100
    Aug 21 '14 at 21:54
  • @E Carter Young: That's very unfortunate, as I can't use a GUI that works on any system easily.
    – empedokles
    Aug 21 '14 at 21:58

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.