Kivy FileChooser doubleclick

扶醉桌前 提交于 2020-01-07 03:14:10

问题


Could somebody post a small working example of a kivy Filechooser with the following simple doubleclick function: doubleclicking on a file will print out the filename?


回答1:


Here is an example of that.

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()



回答2:


I think it is simpler than that.

FileChooser has an argument dirselect. By default it is False making it single-click. If you change dirselect to True, it works as double-click.

For example, in kivy language

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

For example, in python language

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

Hope it helps somebody



来源:https://stackoverflow.com/questions/42393319/kivy-filechooser-doubleclick

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!