我正在尝试添加一个def __init__(self)代码,当我运行kivy程序时,我得到了这个:
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'
Run Code Online (Sandbox Code Playgroud)
这是代码:它def __init__(self)是一个PlayerImage类,它是我试图在屏幕上移动的小部件
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/"]
Run Code Online (Sandbox Code Playgroud)
我没有使用kv lang文件,所以这里是我的构建代码:
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
''')
Run Code Online (Sandbox Code Playgroud)
编辑:添加kivy标签
更换:
def __init__(self):
super().__init__()
Run Code Online (Sandbox Code Playgroud)
附:
def __init__(self, **kwargs):
super(PlayerImage, self).__init__(**kwargs)
Run Code Online (Sandbox Code Playgroud)
您正在创建对象的子类,而不传递Kivy所需的关键字参数.
我也不认为__init__()Kivy需要它,我认为它可能会从父母那里自动查找,但我不确定.
编辑:就像Kevin在评论中所说,因为你使用的是Python 3,你可以使用零参数super()同样有效.
| 归档时间: |
|
| 查看次数: |
4908 次 |
| 最近记录: |