【发布时间】:2018-01-06 21:36:35
【问题描述】:
Kivy manual 中是使用带有 kivy 语言的 FileChooser 的示例。我只想在 python 代码中使用 FileChooser。当我用鼠标标记目录时,按下按钮 Select Dir 并且实际值在变量 FileChooser.path 中。不使用此按钮的选择没有结果。 在示例中的 kv 文件中使用了事件 on_selection,我将此事件与我的函数绑定,但没有效果。
我的问题:
- 如何仅使用鼠标获得路径值?
- 哪个类使用事件on_selection?
谢谢!
class Explorer(BoxLayout):
def __init__(self, **kwargs):
super(Explorer,self).__init__(**kwargs)
self.orientation = 'vertical'
self.fichoo = FileChooserListView(size_hint_y = 0.8)
self.add_widget(self.fichoo)
control = GridLayout(cols = 5, row_force_default=True, row_default_height=35, size_hint_y = 0.14)
lbl_dir = Label(text = 'Folder',size_hint_x = None, width = 80)
self.tein_dir = TextInput(size_hint_x = None, width = 350)
bt_dir = Button(text = 'Select Dir',size_hint_x = None, width = 80)
bt_dir.bind(on_release =self.on_but_select)
self.fichoo.bind(on_selection = self.on_mouse_select)
control.add_widget(lbl_dir)
control.add_widget(self.tein_dir)
control.add_widget(bt_dir)
self.add_widget(control)
return
def on_but_select(self,obj):
self.tein_dir.text = str(self.fichoo.path)
return
def on_mouse_select(self,obj):
self.tein_dir.text = str(self.fichoo.path)
return
def on_touch_up(self, touch):
self.tein_dir.text = str(self.fichoo.path)
return super().on_touch_up(touch)
return super().on_touch_up(touch)
【问题讨论】:
标签: python kivy kivy-language