Kivy:在将自定义窗口小部件添加到Kivy布局时输入错误,缺少参数

时间:2015-11-21 18:03:31

标签: python kivy

我有一个自定义但非常蹩脚的图标小部件:

.py
class Icon(Widget, ButtonBehavior):
    image = StringProperty('path')
    text = StringProperty('string')
    destiny = ObjectProperty('data dictionary')

    def on_press(self, destiny):
        MainView.open(destiny)

.kv
<Icon>:
    text: 'text'
    image: 'path'
    canvas:
        Rectangle:
            source: image
        Label:
            text: 'text'
    on_press: open(self)

并根据字典上的数据列出它们:

.py
class IconList(ListView):
    iconlist = ObjectProperty(StackLayout)

    def open(self, address):
        for icon in sorted(dict.keys()):
            icon = Icon(image='/' + icon + '.jpg',
                         text=address['content'][icon]['text'],
                         destiny=address['content'][icon])
            self.iconlist.add_widget(icon)

.kv
<IconList>:
    iconlist: iconlist
    Label:
        id: description
        text: 'this is a list of available icons...'
    StackLayout:
        id: iconlist

某些调试告诉我图标对象正在运行并正确设置所有数据,但我收到了消息:

TypeError: add_widget() missing 1 required positional argument: 'widget'

&#39;类型错误&#39;我想也许Icon类没有被识别为Widget类,但我不知道修复它。

0 个答案:

没有答案