I have a custom widget PlaylistView
in kivy which should take another custom widget as argument for its init method:
class PlaylistView(Widget):
def __init__(self, node, **kwargs): # (originally:) node: GridNode,... (custom node, removed for min. reproducable exmple but still yields the same error)
super().__init__(**kwargs)
self.node = node
...
But whenever I try to create an instance of it, for example: PlaylistView(1)
, PlaylistView(GridNode('test'))
or PlaylistView("test")
(no matter what I pass as argument), I get the following error:
Traceback (most recent call last):
File "C:/Users/Maximilian.Wolf/PycharmProjects/MiaudioPyler/main.py", line 215, in <module>
PlaylistView("test")
File "C:/Users/Maximilian.Wolf/PycharmProjects/MiaudioPyler/main.py", line 157, in __init__
super().__init__(**kwargs)
File "C:\Users\Maximilian.Wolf\Miniconda3\envs\MiaudioPyler\lib\site-packages\kivy\uix\widget.py", line 359, in __init__
self.apply_class_lang_rules(
File "C:\Users\Maximilian.Wolf\Miniconda3\envs\MiaudioPyler\lib\site-packages\kivy\uix\widget.py", line 463, in apply_class_lang_rules
Builder.apply(
File "C:\Users\Maximilian.Wolf\Miniconda3\envs\MiaudioPyler\lib\site-packages\kivy\lang\builder.py", line 541, in apply
self._apply_rule(
File "C:\Users\Maximilian.Wolf\Miniconda3\envs\MiaudioPyler\lib\site-packages\kivy\lang\builder.py", line 663, in _apply_rule
self._apply_rule(
File "C:\Users\Maximilian.Wolf\Miniconda3\envs\MiaudioPyler\lib\site-packages\kivy\lang\builder.py", line 659, in _apply_rule
child = cls(__no_builder=True)
TypeError: __init__() missing 1 required positional argument: 'node'
I also tried using node=None
in init, same results.
Could this be something to do with kivy or how I call super().__init__
?
EDIT
I tried this seperately, which works, still no clue what's causing the error.
from kivy.uix.widget import Widget
class PlaylistView(Widget):
def __init__(self, node, **kwargs):
super().__init__(**kwargs)
self.node = node
PlaylistView(1)
EDIT 2
More info:
What I did and wasn't showing in the example is loading a bunch of kv-files with Builder.load_file(..
. Commenting this out also makes the error go away.
The traceback must be read from top to bottom. The error is is file "C:\Users\Maximilian.Wolf\Miniconda3\envs\MiaudioPyler\lib\site-packages\kivy\lang\builder.py", line 659. The line
child = cls(__no_builder=True)
is triggering the error. Since kivy uses factories, it is not clear what is causing the error, but the parameter is missing in that call, and not in your call to super().__init__
.
You should also include *args
in the signature and call to super: factories may use the function signatures.