python – Kivy FileChooser:仅列出目录
作者:互联网
如何仅列出Kivy FileChooser中的目录?我玩过滤器:
filters: ['Directories, not files!']
但文件再次列出.我关于回调过滤器,但没有找到示例.
我的Kv代码:
<Saveto>:
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...
解决方法:
这是一个例子:
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("""
<MyWidget>:
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()
请注意,该属性称为过滤器,而不是过滤器,因为它是一个列表,例如回调列表.
标签:kivy,python,python-3-x,user-interface,filechooser 来源: https://codeday.me/bug/20190829/1761526.html