Tree View“类型”对象不可迭代

时间:2020-10-31 19:02:28

标签: python kivy

尝试为弹道计算器创建树形视图并出现此错误。 'type'对象在本节中是不可迭代的-> def create_tree_view_branch(self):我是新手,所以我确定我没有正确创建它,但这是到目前为止我一直在努力的唯一问题持续了很长时间。

class TreeViewGroup(Popup):
tree_view = ObjectProperty(None)
tv = ObjectProperty(None)
filter_text = StringProperty('')
tree = ListProperty([])

def __init__(self, **kwargs):
    super(TreeViewGroup, self).__init__(**kwargs)
    self.create_tree_view_root()
    rows = ['test{}'.format(i) for i in range(1, 20)]**strong text**
    self.tree = [{'node_id': r, 'children': []} for r in rows]
    self.create_tree_view_branch()


def create_tree_view_root(self):
    self.tv = TreeView(root_options=dict(text=""),
                       hide_root=False,
                       indent_level=4)


def create_tree_view_branch(self):
    for branch in object:
        populate_tree_view_branch(self.tv, None, branch)
    self.tree_view.add_widget(self.tv)

def on_open(self, *args):
    self.filter_text = App.get_running_app().root.name.text
    self._request_keyboard()
    self.ti.focus = True

def dismiss_callback(self):
    if self._keyboard is not None:
        self._keyboard.release()
    self.tree_view.clear_widgets()
    self.dismiss()
    App.get_running_app().root.name.focus = True

def _request_keyboard(self):
    self._keyboard = Window.request_keyboard(self._keyboard_closed, self)
    self._keyboard.bind(on_key_down=self._on_keyboard_down)
    if self.tv.selected_node is None:
        self.tv.select_node(self.tv.root.nodes[0])

def _keyboard_closed(self):
    self._keyboard.unbind(on_key_down=self._on_keyboard_down)
    self._keyboard.release()
    self._keyboard = None

def _on_keyboard_down(self, keyboard, keycode, text, modifiers):
    node = self.tv.selected_node
    _, key = keycode
    if key in ('down', 'up'):
        parent = node.parent_node
        ix = parent.nodes.index(node)
        nx = ix+1 if key == 'down' else ix-1
        next_node = parent.nodes[nx % len(parent.nodes)]
        self.tv.select_node(next_node)
        self.scroll.scroll_to(next_node)
    elif key in ('enter', 'numpadenter'):
        App.get_running_app().root.name.text = node.text
        print(node.text)
        self.dismiss_callback()

1 个答案:

答案 0 :(得分:0)

变量object未在您的代码中定义。因此,python将object视为Python object,这会返回一个空对象。