I have a question about classes, subclasses and inheritance in Python.
I've been using Tkinter for GUI development for some time and have decided to learn how to use Kivy. In the Kivy documentation I came across a line of code that didn't make any sense to me. It is as follows (note, GridLayout
is a class I imported from the kivy module):
class LoginScreen(GridLayout):
def __init__(self, **kwargs):
super(LoginScreen, self).__init__(**kwargs)
The super
call on LoginScreen and self instead of GridLayout really confuses me! Is the class inheriting itself? What is going on?
In Tkinter I would write something like (note again that, tk.Frame
is a class imported from the Tkinter module):
class LoginScreen(tk.Frame)
def __init__(self, parent):
super().__init__(parent)
As I typed out these two examples I noticed that I am not passing anything into super()
. Are the default parameters of the super method the name of the class and self? i.e. is the above akin to writing...
class LoginScreen(tk.Frame):
def __init__(self, parent):
super(LoginScreen, self).__init__(parent)
If they are different can you explain why they are different, but if they are the same can you explain a little more in-depth as to how super()
does what it does (beyond simply it inherits the methods and attributes of the parent class)?