Python Forum

Full Version: Why call import twice?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

I'm learning about TclTk, and was wondering why the tkintter module is imported twice:

from tkinter import *
from tkinter import ttk
Thank you.
The second import is redundant.
and the first import is flooding the namespace https://python-forum.io/Thread-Namespace...th-imports
(May-23-2019, 09:37 PM)Yoriz Wrote: [ -> ]The second import is redundant
It's not redundant in this case,as ttk widgets was added to Tkinter later.
Therefor are from tkinter import * and from tkinter import tkk different commands that import things from different modules.
In doc they describe a override way doc
tkk doc Wrote:To override the basic Tk widgets, the import should follow the Tk import:
from tkinter import *
from tkinter.ttk import *
It's bad that they did it this way with the usage * in doc.
Could have explain that it's different without using *
import tkinter as tk
from tkinter import ttk
...
b1 = tk.Button(...)
b2 = ttk.Button(...)
Thanks snippsat.
(May-23-2019, 11:04 PM)snippsat Wrote: [ -> ]It's not redundant in this case,as ttk widgets was added to Tkinter later.

Thanks for the infos.