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

empedokles
  • 4,023

2 Answers2

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

Xweque
  • 1,103
Lin Xu
  • 11
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.

eyoung100
  • 975