1
I am developing a small application in Python and I came across a question that I could not draw a concrete conclusion about why this should happen. Simply put, the problem is this::
The following code works normally:
from kivy.app import App
from kivy.uix.widget import Widget
class MyKeyboardListener(Widget):
pass
class Aplicativo(App):
def build(self):
return MyKeyboardListener()
if __name__ == '__main__':
Aplicativo().run()
The problem actually appears when I create the class constructor method, in which case the application no longer works
from kivy.app import App
from kivy.uix.widget import Widget
class MyKeyboardListener(Widget)
def __init__(self): <-- após incluir este o problema acontece
pass
class Aplicativo(App):
def build(self):
return MyKeyboardListener()
if __name__ == '__main__':
Aplicativo().run()
The application only works again when I call the mother constructor method, in this case "Widget"
from kivy.app import App
from kivy.uix.widget import Widget
class MyKeyboardListener(Widget)
def __init__(self):
super.__init__(): <-- Construtor da Mãe
class Aplicativo(App):
def build(self):
return MyKeyboardListener()
if __name__ == '__main__':
Aplicativo().run()
The question in question is why does the program stop working when I declare the constructor (even empty) of the Mykeyboardlistener class? and why the same works again when I call the super class builder?
the mother class constructor must initiate variables or flame some method that arrow some parameter within the object, vc declaring the class constructor of the daughter class goes on to write the inherited, so ñ works without the super call()
– Elton Nunes
And why don’t you think you should or shouldn’t need to declare?
– Maniero
vc only declares if you want to put extra functions, in the case of example script nothing is added or changed, so code is useless
– Elton Nunes