我在线查看,我仍然坚持如何将TreeView的'on_node_expand'绑定到一个函数。
是否可以获得正确的语法?
def createSubNode(elemObj,designTree,parent=None):
if type(elemObj) is (designClass.PathGroup):
pass
else:
for (name, obj) in elemObj.items():
subroot = designTree.add_node(TreeViewLabel(text=name,font_size=12),parent)
subroot.fbind('on_node_expand', bind_object)
createSubNode(obj,designTree,subroot)
def bind_object(node):
print("testing")
if __name__ == '__main__':
from kivy.app import App
class TestApp(App):
def build(self):
designTree = TreeView(root_options=dict(text='Designs',font_size=12))
designTree.size_hint = (1,None)
designTree.bind(minimum_height=designTree.setter('height'))
createSubNode(dsgnManObj, designTree)
svRoot = ScrollView(size=(Window.width, Window.height))
svRoot.add_widget(designTree)
root = BoxLayout(orientation ='horizontal')
root.add_widget(svRoot)
return root
TestApp().run()
答案 0 :(得分:0)
on_node_expand
是TreeView上的事件,而不是节点上的事件,因此您不需要将其绑定到subroot
个对象上,而只需绑定在designTree
对象上。