Python Forum
Why call import twice? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Why call import twice? (/thread-18603.html)



Why call import twice? - Winfried - May-23-2019

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.


RE: Why call import twice? - micseydel - May-23-2019

The second import is redundant.


RE: Why call import twice? - Yoriz - May-23-2019

and the first import is flooding the namespace https://python-forum.io/Thread-Namespace-flooding-with-imports


RE: Why call import twice? - snippsat - May-23-2019

(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(...)



RE: Why call import twice? - micseydel - May-23-2019

Thanks snippsat.


RE: Why call import twice? - Winfried - May-24-2019

(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.