【问题标题】:Kivy FileChooser doubleclickKivy FileChooser 双击
【发布时间】:2017-02-22 13:49:07
【问题描述】:

有人可以发布一个带有以下简单双击功能的 kivy Filechooser 的小型工作示例:双击文件将打印出文件名?

【问题讨论】:

    标签: python kivy


    【解决方案1】:

    这是一个例子。

    from kivy.app import App
    from kivy.uix.filechooser import FileChooserListView
    from kivy.uix.boxlayout import BoxLayout
    
    
    class MyFileChooser(FileChooserListView):
    
        def on_submit(*args):
            print(args[1][0])
    
    
    class MyLayout(BoxLayout):
    
        def __init__(self,**kwargs):
            super(MyLayout,self).__init__(**kwargs)
            # filter added. Since windows will throw error on sys files
            self.fclv = MyFileChooser(filters= [lambda folder, filename: not filename.endswith('.sys')])
            self.add_widget(self.fclv)
    
    
    class MyApp(App):
    
        def build(self):
            return MyLayout()
    
    
    MyApp().run()
    

    【讨论】:

    • 您使用的是哪个版本的 Kivy?
    • @picibucor v1.9.1。对不起,我忘了打印文件名:D 我会更新
    • 您的代码对我不起作用。我正在使用最新的夜间版本(2017.02.22)
    • @picibucor 好的,它应该仍然可以工作。有任何错误吗?
    • @picibucor 尝试从MyFileChooser 中取出path='.'。在那一天,这方面存在一些问题。
    【解决方案2】:

    我认为它比那更简单。

    FileChooser 有一个参数dirselect。默认情况下,它是 False 使其单击。如果你把dirselect改成True,就相当于双击了。

    例如,在kivy语言中

    BoxLayout:
        FileChooserIconView:
            size_hint: (0.3, 0.4)
            dirselect: True
    
    

    以python语言为例

    FileChooserListView(size_hint_x=0.3, size_hint_y=0.4, dirselect=True)
    

    希望对某人有所帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-15
      • 2017-07-19
      • 1970-01-01
      • 2018-07-01
      • 2019-08-11
      • 1970-01-01
      相关资源
      最近更新 更多