Importing a class into another class in Python
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.
No comments:
Post a Comment