scope acting weird

Discussion in 'Python' started by Gabriel B., May 1, 2005.

  1. Gabriel B.

    Gabriel B. Guest

    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
    Gabriel B., May 1, 2005
    #1
    1. Advertising

  2. Gabriel B.

    Mike Meyer Guest

    "Gabriel B." <> 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 <> http://www.mired.org/home/mwm/
    Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
    Mike Meyer, May 1, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David
    Replies:
    5
    Views:
    379
    Juan T. Llibre
    Apr 21, 2005
  2. Jeff Epler
    Replies:
    0
    Views:
    497
    Jeff Epler
    Aug 20, 2004
  3. Jeff Epler
    Replies:
    0
    Views:
    444
    Jeff Epler
    Aug 23, 2004
  4. Merrigan

    ftplib acting weird

    Merrigan, May 4, 2007, in forum: Python
    Replies:
    1
    Views:
    384
    Carlos Hanson
    May 7, 2007
  5. Imran Sadat
    Replies:
    4
    Views:
    415
    Imran
    Jan 11, 2008
Loading...

Share This Page