confused about __init__ method inside of def __init__ confused about __init__ method inside of def __init__ tkinter tkinter

confused about __init__ method inside of def __init__


CardShuffling(tk.Tk) only makes the class CardShuffling a child of tk.Tk. your new class inherits all the methods of this class.

but if you create a new object you still have to call the constructor of that base class (with the new object as argument). imagine there is a line self.a = 0 in the constructor of the parent class. your child class has to run this line when you initialize a new instance; CardShuffling(tk.Tk) can not do that for you; you need to run __init__ of the parent class.

the usual way to do that in python 3 is

def __init__(self):    super().__init__()

which is the same in this case as

def __init__(self):    tk.Tk.__init__(self)

maybe this article on inheritance helps and there is even a book chapter freely available.