25

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.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
Benjamin Boyce
  • 305
  • 1
  • 4
  • 11

3 Answers3

48

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

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
2

For python version 2.7, to import all packages:

from Tkinter import *
from ttk import *

Or you can only import ttk.

import ttk

For python version 3, to import all packages:

import tkinter as tk 
from tkinter import ttk 
Mijanur Rahman
  • 1,094
  • 1
  • 11
  • 20
0

In Python 2.7.16, ttk is its own package:

import Tkinter

import ttk

from Tkinter import *

from ttk import *