scope acting weird
Mike Meyer
mwm at mired.org
Sun May 1 17:57:31 EDT 2005
"Gabriel B." <gabriel.barros at gmail.com> writes:
> i have the following code:
>
> Ui.py:
> import Tkinter as Tk
> import UiMainScreen
>
> UiMainScreen.py:
> class UiMainScreen( Tk.Frame ):
> ....
>
> and i get the following error:
> File "UiMainScreen.py", line 1, in ?
> class UiMainScreen(Tk.Frame):
> NameError: name 'Tk' is not defined
>
> isn't Tk supposed to be imported globaly?
No. import only affects thye module it's in. You need to add "import
Tk" to UiMainScreen.py.
> And If i import Tkinter again inside every other file, will it be
> really imported several times and be independent in each file or the
> python interpreter just use the subsequent imports to know where to
> propagate stuff?
The module is only imported once. The second and further imports link
the name Tk in the importing module to the Tk module already imported.
<mike
--
Mike Meyer <mwm at mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
More information about the Python-list
mailing list