Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

problems importing ttk from tkinter in python 2.7

Tags:

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.

like image 411
Benjamin Boyce Avatar asked Jun 01 '14 21:06

Benjamin Boyce


People also ask

Why tkinter is not working in Python?

The easiest way to fix this problem is by upgrading your python to use python 3. If upgrading python is not an option, you only need to rename your imports to use Tkinter (uppercase) instead of tkinter (lowercase). Output: As a result, this window proves that your python installation includes the Tkinter module.

What is the difference between tkinter and tkinter TTK?

Tkinter widgets are used to add Buttons, Labels, Text, ScrollBar, etc., however, tkinter. ttk supports a variety of widgets as compared to tkinter widgets. Tkinter. ttk doesn't support Place, Pack() and Grid(), thus it is recommended to use tkinter widget with ttk.

What does import TTK do in Python?

The significance of "import *" represents all the functions and built-in modules in the tkinter library. By importing all the functions and methods, we can use the inbuilt functions or methods in a particular application without importing them implicitly.


1 Answers

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

like image 156
Bryan Oakley Avatar answered Sep 28 '22 18:09

Bryan Oakley