Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why call import twice?
#1
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.
Reply
#2
The second import is redundant.
Reply
#3
and the first import is flooding the namespace https://python-forum.io/Thread-Namespace...th-imports
Reply
#4
(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(...)
Reply
#5
Thanks snippsat.
Reply
#6
(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.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020