Python 高度:“32dp” #发布时:dropdown3.open(self) 发布时:root.display\u account\u group() 盒子布局: id:content\u区域 尺码提示y:30 标签: 尺寸提示:1
有人能帮我吗?第一件事。你必须为不同的类别制作不同的列表Python 高度:“32dp” #发布时:dropdown3.open(self) 发布时:root.display\u account\u group() 盒子布局: id:content\u区域 尺码提示y:30 标签: 尺寸提示:1,python,python-2.7,kivy,kivy-language,Python,Python 2.7,Kivy,Kivy Language,有人能帮我吗?第一件事。你必须为不同的类别制作不同的列表 # male name list fetch from database rows_male = [('Andrew'),('Daniel'),('Ebenezer')] #girl name list fetch from database rows_girl = [('Atarah'),('Abigail'),('Adriel')] #Dog name list fetch from database rows_dog = [('
# male name list fetch from database
rows_male = [('Andrew'),('Daniel'),('Ebenezer')]
#girl name list fetch from database
rows_girl = [('Atarah'),('Abigail'),('Adriel')]
#Dog name list fetch from database
rows_dog = [('Abby'),('Flash'),('Penny')]
然后做一个能容纳每棵树的词汇表
treeEffectType = {'Male': [], 'Female': [], 'Dog': []}
for r in rows_male:
treeEffectType['Male'].append({'node_id': r, 'children': []})
for r in rows_girl:
treeEffectType['Female'].append({'node_id': r, 'children': []})
for r in rows_dog:
treeEffectType['Dog'].append({'node_id': r, 'children': []})
然后编辑一点您的TreeViewEffectType类:
class TreeviewEffectType(Popup):
...
def __init__(self, type, **kwargs):
super(TreeviewEffectType, self).__init__(**kwargs)
self.type = type
self.tv = TreeView(root_options=dict(text=""),
hide_root=False,
indent_level=4)
for branch in treeEffectType[self.type]:
populate_tree_view_effect_type(self.tv, None, branch)
#self.remove_widgets()
self.treeviewEffectType.add_widget(self.tv)
Clock.schedule_once(self.update, 1)
...
def filter(self, f):
self.treeviewEffectType.clear_widgets()
self.tv = TreeView(root_options=dict(text=""),
hide_root=False,
indent_level=4)
new_tree = []
for n in treeEffectType[self.type]:
if f.lower() in n['node_id'].lower():
new_tree.append(n)
for branch in new_tree:
populate_tree_view_effect_type(self.tv, None, branch)
self.treeviewEffectType.add_widget(self.tv)
我们需要第一个文本输入的值,因此您必须将该属性保存在kv中:
...
<AccountGroupPopup>:
title: ""
size_hint: None, None
size: 500, 350
auto_dismiss: False
name_label: name_label
name_txt: name_txt
category_text: category_text
...
谢谢回复。我更新了代码。我不知道我在哪里犯了错误我得到了错误文件“/usr/lib/python2.7/dist packages/kivy/uix/widget.py”,第532行,在add_widget%(widget,parent))kivy.uix.widget.WidgetException:无法添加,它已经有一个父@gunjantalwar对不起,昨天我写我的答案时,我在TreeViewEffectType类的init方法中犯了一个缩进错误,现在我已经更新了它
class TreeviewEffectType(Popup):
...
def __init__(self, type, **kwargs):
super(TreeviewEffectType, self).__init__(**kwargs)
self.type = type
self.tv = TreeView(root_options=dict(text=""),
hide_root=False,
indent_level=4)
for branch in treeEffectType[self.type]:
populate_tree_view_effect_type(self.tv, None, branch)
#self.remove_widgets()
self.treeviewEffectType.add_widget(self.tv)
Clock.schedule_once(self.update, 1)
...
def filter(self, f):
self.treeviewEffectType.clear_widgets()
self.tv = TreeView(root_options=dict(text=""),
hide_root=False,
indent_level=4)
new_tree = []
for n in treeEffectType[self.type]:
if f.lower() in n['node_id'].lower():
new_tree.append(n)
for branch in new_tree:
populate_tree_view_effect_type(self.tv, None, branch)
self.treeviewEffectType.add_widget(self.tv)
...
<AccountGroupPopup>:
title: ""
size_hint: None, None
size: 500, 350
auto_dismiss: False
name_label: name_label
name_txt: name_txt
category_text: category_text
...
...
class AccountGroupPopup(Popup):
category_label = ObjectProperty(None)
category_text = ObjectProperty(None)
name_label = ObjectProperty(None)
name_txt = ObjectProperty(None)
popupGroupAccount = ObjectProperty(None)
popupEffect = {}
...
def __init__(self, obj, **kwargs):
super(AccountGroupPopup, self).__init__(**kwargs)
self.mode = obj.mode
if obj.mode == "Add":
self.col_data[0] = ''
self.col_data[1] = ''
self.col_data[2] = ''
self.col_data[3] = 'Select Category'
self.col_data[4] = 'Select Name'
self.popupEffect['Male'] = TreeviewEffectType('Male')
self.popupEffect['Male'].popup5 = self
self.popupEffect['Female'] = TreeviewEffectType('Female')
self.popupEffect['Female'].popup5 = self
self.popupEffect['Dog'] = TreeviewEffectType('Dog')
self.popupEffect['Dog'].popup5 = self
...
def display_effect_type(self, instance):
if len(self.category_text.text) > 0:
if self.popupEffect[self.category_text.text] is None:
self.popupEffect[self.category_text.text] = TreeviewEffectType(self.category_text.text)
self.popupEffect[self.category_text.text].popup5 = self
self.popupEffect[self.category_text.text].filter(instance.text)
self.popupEffect[self.category_text.text].open()