Importing a class into another class in Python
Question: as I'm still learning python I came up to a problem.

Why does this work:

    
    
    class SomeOtherClass(object):
        def __init__(self):
            self.number = 10
            print(self.number)
    
        def increase(self):
            self.number += 1
            print(self.number)
    
    class MyMainClass(object):
        def __init__(self):
            self.otherClass = MyClass()
    
    app = MyMainClass() #Output: 10
    app.otherclass.increase() #Output: 11
    

but this doesn't:

    
    
    from tkinter import *
    
    class MyMainClass(object):
        def __init__(self):
            self.tk = Tkinter() # <-- Error: see below.
    
    app = MyMainClass()
    app.tk.title("My window")
    ...
    

Both times I include a class, but in the second example it says:

> NameError: global name 'Tkinter' is not defined

Where's the difference between those examples and how can I solve this, so I'm
able to use tkinter in my class?

Thanks for your help.


Answer: Perhaps you meant `Tk()`? the `tkinter` module on Python 3.x does not seem to
contain a class `Tkinter`.

As to the meaning of your question and example... well, the examples are
absolutely irrelevant, and the question should simply be "why can't I create
an instance of `Tkinter`" or something.

**Python Lesson:** This is also a good example of why it's a bad idea to use
star imports (i.e `from <module> import *`, because `*` looks like a star).
This imports everything from `tkinter`, but doesn't let you know if something
you thought was there actually isn't

    
    
    from tkinter import *
    

whereas this

    
    
    from tkinter import Tkinter
    

would have immediately pointed out that (the class) `Tkinter` does not exist
in `tkinter`. Another option that some seem to prefer (incl. myself in some
cases), is `import tkinter` followed by `tkinter.Tk()`, which has the
advantage that it's obvious where a class comes from. Futhermore,
[PEP8](http://www.python.org/dev/peps/pep-0008/#imports) also discourages the
use of star imports (referring to them as "wildcard imports").

