python - kivy FileChooserListView on_selection 事件未按预期工作
问题描述
我试图通过绑定到更新文本标签的方法来观察selection
FileChooserListView 对象的属性(ObservableList) 。on_selection
根据我对 kivy 文档的解释,我认为下面的代码可以工作,但是没有多少点击或双击文件名会导致标签被更新或打印语句被执行。我是否误解了有关on_<property>
变更事件的文档?
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.filechooser import FileChooserListView
class FCApp(App):
def build(self):
my_layout = AppLayout()
return my_layout
class AppLayout(BoxLayout):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.orientation = 'vertical'
self.lbl = Label(size_hint_y=0.1, text='Select a file...')
self.fc = FileChooserListView(size_hint_y=0.9)
# Bind changes to the file chooser's selection property to a function
self.fc.bind(on_selection=self.update_label)
self.add_widget(self.lbl)
self.add_widget(self.fc)
def update_label(self, obj):
print('update_label_called')
self.lbl.text = str(obj.selection)
if __name__ == '__main__':
FCApp().run()
解决方案
推荐阅读
- google-play - 从 Google Play 控制台删除草稿应用程序的包名称后,我可以在新应用程序中重新使用它吗?
- tensorflow - 在 Cloud ML 上运行的 Tensorflow 对象检测出错:没有模块 object_detection.train
- rest - Grails REST POST 失败,元素具有备用标识符列
- visual-studio-code - 在 VS Code 中,在活动组下显示状态栏?
- python - 根据 ID 值删除/保留 numpy 数组行
- html - 选中的复选框不会改变 CSS
- android - 如何使用两个recyclerview(一个垂直,另一个水平)
- django - Heroku 和 Django 2.x ModuleNotFoundError:没有名为“rest_auth”的模块
- python - 为什么我的数据框还是空的?
- amazon-web-services - 如何将特殊数据附加到 AWS SES 电子邮件发送?