0

Python applications using TK GUIs usually call the following import statements:

from tkinter import *
from tkinter import ttk

Isn't calling from tkinter import ttk redundant? I thought ttk would already be imported by calling from tkinter import *

Please explain why ttk needs to be imported separately?

(I already understand that it has "improved widgets". I want to understand why the improved widgets aren't accessible from the from tkinter import * call.)

user12711
  • 693
  • 1
  • 7
  • 21

1 Answers1

4

If you go to your python installed location, you will find that in the python library, tkinter is a folder instead of a .py file. So when you use from tkinter import *, you actually only imported things in your-python-location/lib/tkinter/__init__.py. Things like ttk are actually separate files in tkinter folder(e.g. lib/tkinter/ttk.py, lib/tkinter/scrolledtext.py etc.) Therefore, from tkinter import * and from tkinter import tkk are different commands that import things from different module.

Mia
  • 2,466
  • 22
  • 38
  • This tread has been marked as duplicate. Anyhow, an answer within another thread says, "The syntax from module import something doesn't import submodules (Which, as another answer stated, not defined in `__all__` " So, would that be __init__.py within a folder, or an `__all__` possibly within another x.py file – user12711 Feb 18 '17 at 21:41