scope acting weird

G

Gabriel B.

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?
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?

Thanks,
Gabriel
 
M

Mike Meyer

Gabriel B. said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top