如何仅列出Kivy FileChooser中的目录?我玩过滤器:
filters: ['Directories, not files!']
但文件再次列出.我关于回调过滤器,但没有找到示例.
我的Kv代码:
: select: select chooser: chooser orientation: 'vertical' FileChooserIconView: id: chooser size_hint_y: 0.9 rootpath: home dirselect: True filters: ['How to list only folders?'] Button: ...select button...
Nykakin.. 5
这是一个例子:
from kivy.app import App from kivy.uix.boxlayout import BoxLayout from kivy.lang import Builder from os.path import join, isdir Builder.load_string(""": FileChooserListView: filters: [root.is_dir] """) class MyWidget(BoxLayout): def is_dir(self, directory, filename): return isdir(join(directory, filename)) class MyApp(App): def build(self): return MyWidget() if __name__ == '__main__': MyApp().run()
请注意,该属性被调用filters
,而不是filter
,因为它是一个列表,例如,一个回调列表.
这是一个例子:
from kivy.app import App from kivy.uix.boxlayout import BoxLayout from kivy.lang import Builder from os.path import join, isdir Builder.load_string(""": FileChooserListView: filters: [root.is_dir] """) class MyWidget(BoxLayout): def is_dir(self, directory, filename): return isdir(join(directory, filename)) class MyApp(App): def build(self): return MyWidget() if __name__ == '__main__': MyApp().run()
请注意,该属性被调用filters
,而不是filter
,因为它是一个列表,例如,一个回调列表.