Benjamin Boyce
Benjamin Boyce

Reputation: 305

problems importing ttk from tkinter in python 2.7

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.

Upvotes: 25

Views: 41386

Answers (3)

Mijanur Rahman
Mijanur Rahman

Reputation: 1182

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 

Upvotes: 2

Ravi Chandran
Ravi Chandran

Reputation: 11

In Python 2.7.16, ttk is its own package:

import Tkinter

import ttk

from Tkinter import *

from ttk import *

Upvotes: 0

Bryan Oakley
Bryan Oakley

Reputation: 385900

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

Upvotes: 48

Related Questions