Skip to main content
 首页 » 编程设计

python之Kivy 文件选择器问题

2024年11月01日15powertoolsteam

我正在使用基于 Kivy 示例演示的文件选择器:

.kv 文件:

        FileChooserListView: 
            id: list_view_tab 
            path: '.' 
            on_selection: nada = app.loader(list_view_tab.selection) 
 
        FileChooserIconView: 
            id: icon_view_tab 
            show_hidden: True 
            on_selection: nada = app.loader(icon_view_tab.selection) 
 
... 
 
    TextInput: 
        size_hint: (None, 1) 
        id: filtro 
        text: '*.py' 
        multiline: False 
        on_text: list_view_tab.filters = icon_view_tab.filters = text.split(',') 

.py 代码中没有对这些小部件的直接引用,它显示文件系统在两种方式都正常。

我有这些问题:

  • 过滤器不起作用。我错过了什么?

  • 在 FileChooserListView 中有列名 Name 和 Size。我如何将这些更改为其他语言?

  • 如何通过单击选择文件?

请您参考如下方法:

The filter doesn't work. What have I missed?

您为两个 FileChooserListView 设置了 filter 属性,但这似乎不存在。您应该改为设置 filters 属性,该属性必须是字符串列表。这记录在案 here在 kivy 文档中。

In the FileChooserListView there are the column names Name and Size. How can I change these for other languages?

我不认为这在 api 中公开,尽管它可能应该公开。现在,您可能必须更改您的 kivy 源。相关行在kivy/data/style.kv的FileChooserListView规则中,可以找到here在 kivy 的 github 上。

How can I select files by single click?

我不确定最佳方法,但我可能会查看 FileChooserListView 的 selection 属性。作为一个 kivy 属性,这将在选择更改时调用方法 on_selection,因此您可以将所需的行为放在那里。

选择更改的确切方式和时间可能有些繁琐,但这似乎是正确的选择。