from tkinter import *
from tkinter import messagebox
I wanted to know that what is the difference between these two. doesn't import * imports all the modules and function from tkinter to the projects then why do we need to import messagebox seperately.
CodePudding user response:
if you've imported all using import *, you no longer need imports for specific modules, but this will use more memory than just importing specific modules
CodePudding user response:
In from tkinter import *
, you can refer to each and every thing in tkinter
module. Because it imports the names directly into the local namespace, it creates the potential for conflicts if you import things from many modules. Therefore, the from tkinter import *
is discouraged.
In from tkinter import messagebox
, which imports just the messagebox
into the local namespace, not everything in tkinter
. This is better because if you list the names you import, you know exactly what you are importing and it's easier to avoid name conflicts.