【发布时间】:2020-06-17 12:52:15
【问题描述】:
我有文件选择器,我想更新文件路径文本输入以供参考。当用户选择文件并单击按钮时,整个文件路径由方法获取。
如何实现更新后的文本输入?
到目前为止,我有:
TextInput:
id: file_path
FileChooserIconView:
id: filechooser
on_selection: file_path.text = self.selection and self.selection[0] or self.path
path: '.'
Button:
id: save
text: 'Save'
然后在.py中
self.ids.save.bind(on_press=lambda x: self.save_file(self.ids.file_path.text))
- 问题 1.- 开始时文本输入为空 - 应填写当前查看的文件夹路径
- 问题 2.- 如果我在启动后进入文件夹,路径不会更新并保持空白。
- 问题 3.- 单击文件(正确更新文件路径)然后单击文件夹后,文本输入未更新。
-
问题 4.- 我是 Python 和 Kivy 的新手,我不知道为什么在 the example "and" & "or" 中 - 它似乎不是逻辑表达式
on_selection: text_input.text = self.selection and self.selection[0] or ''
关于选择的唯一内容是
selection:包含当前选择的文件列表。 selection 是一个只读 ListProperty,默认为 []。
【问题讨论】:
标签: python kivy filechooser