Tkinter on Ubuntu 14.04 seems not to work

16,058

Solution 1

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.

Solution 2

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

Share:
16,058

Related videos on Youtube

empedokles
Author by

empedokles

Updated on September 18, 2022

Comments

  • empedokles
    empedokles over 1 year

    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
    empedokles almost 10 years
    @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
  • eyoung100
    eyoung100 almost 10 years
    Ubuntu is neither Windows nor OSX, therefore the need to install the package. See Bolded Text
  • empedokles
    empedokles almost 10 years
    @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..
  • eyoung100
    eyoung100 almost 10 years
    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.
  • empedokles
    empedokles almost 10 years
    @E Carter Young: That's very unfortunate, as I can't use a GUI that works on any system easily.
  • eyoung100
    eyoung100 almost 10 years
    If you're building a package, include tkinter as a RUNTIME DEPENDENCY of the package. As long as you use proper dependency checking, the OS is irrelevant, ie in Windows, you include TCL/TK in your exe and in linux you let the package manager resolve it
  • empedokles
    empedokles almost 10 years
    @E Carter Young I'm not as advanced yet, to build an .exe. It would have been convenient using it for just a single .py-file.
  • Xweque
    Xweque over 9 years
    You should format Terminal commands as code.