problems importing ttk from tkinter in python 2.7

Benjamin Boyce picture Benjamin Boyce · Jun 1, 2014 · Viewed 35.6k times · Source

I'm working with an example file in a tutorial that asks me to first do two imports:

from tkinter import *
from tkinter import ttk

I get an error. I researched a bit and found that in python 2.7.x I need to capitalize the 't'in tkinter, so I change to:

from Tkinter import *
from Tkinter import ttk. 

the first line no longer gives and error, but I still get error:

ImportError: cannot import name ttk.

I have researched this issue on this site and other places, and cannot seem to understand what this ttk is. I'm further confused by the fact that, when I go to the python interpreter, and I type "help()", then "modules", and then "ttk" it seems to know what it is, and gives me a lot of description, for example: "DESCRIPTION This module provides classes to allow using Tk themed widget set." -however, python won't let me import it.

Answer

Bryan Oakley picture Bryan Oakley · Jun 1, 2014

In python 2.7, ttk is its own package:

import Tkinter
import ttk

This is documented in the official python documentation: https://docs.python.org/2/library/ttk.html#module-ttk