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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With