I've always asked myself, why is there a way to import a certain function from a module,
example: from tkinter import ttk
instead of just importing the whole module, --> import tkinter
does it make the program run faster ?
There is no memory or speed difference (the whole module has to be evaluated either way, because the last line could be Y = something_else). It can only matter if you are calling a function a lot of times in a loop (millions or more). Doing the double dictionary lookup will eventually accumulate.
Although import tkinter and from tkinter import ttk both import the entire tkinter module, the latter uses name binding so only ttk is accessible to rest of the code.
For some people this would be the preferred style since it only makes accessible the functions you explicitly stated.
It does however introduce potential name conflicts. Note you can also explicitly import functions and rename them with from tkinter import ttk as tkinter_ttk, a convention that meets the explicit import and is less likely to gave name space collisions.
what is the difference between importing the whole module or importing a certain function?