1

I am installing tkinter on python3 by running: $ sudo apt-get install python3-tk

This returns (translated): $ python3-tk is already in its latest version (3.6.9-1~18.04)

However, when I run:

from tkinter import ttk

I get the following error message:

ImportError: cannot import name 'ttk'

14
  • Are you sure you are using python3? Commented Dec 22, 2019 at 19:23
  • Yes, I'm using python3 for sure. Commented Dec 22, 2019 at 19:25
  • Before you import ttk, you have to import tkinter Commented Dec 22, 2019 at 19:28
  • 1
    what happens when you do import tkinter? Either you will get an error (but not the exact same error) or it will succeed. If it succeeds, what do you get when you next do print(tkinter.__file__)? Commented Dec 22, 2019 at 21:06
  • 1
    @Redline: I don’t think it’s possible. I don’t think that is what actually happened. Commented Dec 22, 2019 at 23:27

1 Answer 1

1

The import should be import tkinter: https://docs.python.org/3.8/library/tkinter.html#tkinter-modules

Sign up to request clarification or add additional context in comments.

5 Comments

First i type: from tkinter import *. Next from tkinter import ttk. It works in my windows computer, but not in Ubuntu
import tkinter won't import ttk. from tkinter import ttk works for fine me (on Windows anyway).
While it's true that you can import tkinter the way you say, that doesn't answer the question. They are trying to import ttk, and the way in which they are doing it is the correct way to import it. In other words, the problem isn't with the import statement.
@BryanOakley Thanks. So have you got any idea of what may be the problem?
True, this should work indeed. Could you check that you have the file ttk.py in /usr/lib/python3.*/tkinter just to verify that it was an issue with the apt-get install?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.