问题
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