I'm trying to add a def __init__(self)
to my code and when I run the kivy program I get this:
Traceback (most recent call last):
File "/Users/acrobat/Desktop/dive/test.py", line 78, in <module>
''')
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/kivy/lang.py", line 1921, in load_string
self._apply_rule(widget, parser.root, parser.root)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/kivy/lang.py", line 2085, in _apply_rule
self._apply_rule(child, crule, rootrule)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/kivy/lang.py", line 2082, in _apply_rule
child = cls(__no_builder=False)
TypeError: __init__() got an unexpected keyword argument '__no_builder'
Here is the code:
The def __init__(self)
is in a PlayerImage
Class which is a widget that I'm trying to move across the screen
class PlayerImage(Image):
angle = NumericProperty(0)
def __init__(self):
super().__init__()
def on_touch_down(self, touch):
# self.currentstate = self.states["person.zip/"]
Animation.cancel_all(self)
angle = degrees(atan2(touch.y - self.center_y,
touch.x - self.center_x))
Animation(center=touch.pos, angle=angle).start(self)
# self.currentstate = self.states["personred/rest.png/"]
I'm not using a kv lang file so here is my build code:
root = Builder.load_string('''
Widget:
Widget:
PlayerImage:
source: './rpgArt/person.zip'
allow_stretch: True
keep_ratio: True
PlayerImage2:
source: './rpgArt/personred.zip'
allow_stretch: True
keep_ratio: True
''')
EDIT: added kivy tag
Replace:
def __init__(self):
super().__init__()
With:
def __init__(self, **kwargs):
super(PlayerImage, self).__init__(**kwargs)
You are creating a subclass of an object without passing the keyword arguments which Kivy requires.
I also don't think the __init__()
is required by Kivy, I think it might look it up automatically for you from the parent, but that I'm not sure with.
Edited: Like Kevin said in the comments since you are using Python 3 you can use the zero arguments of super()
which would be just as valid.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With