Tkinter + import question
Jeff Shannon
jeff at ccvcorp.com
Tue Apr 2 13:49:44 EST 2002
In article <3ca754d4$1_1 at nopics.sjc>, deltapigz at telocity.com
says...
> i am writting a program utilizing Tk as my gui engine, and i have broken
> down sections of the form into modules and loaded them through a main
> script. my only question is in every module i am forced to import the
> Tkinter module, and does this pose consume too much memory?
You do have to import Tkinter (or any other module) into every
module of yours that (directly) uses it. Note that, if you
create a Tkinter object X in Module A, then pass that object to
Module B, Module B doesn't necessarily need to import Tkinter in
order to use object X -- only if you need to use
functions/constants/etc from the Tkinter namespace do you need to
import Tkinter. Object X's methods are in object x's own
namespace, and can be used on their own. (But if you're passing
constants into those methods, you may need to import Tkinter to
get the constants.)
Don't worry about memory consumption, though. Once a module is
imported once in your program, any further imports are *very*
quick and simple. The initial import runs the module and creates
an entry in the sys.modules dictionary. Subsequent imports
simply create a new reference to that sys.modules entry -- they
are *very* lightweight.
--
Jeff Shannon
Technician/Programmer
Credit International
More information about the Python-list
mailing list