如何清除kivy Filechooser的只读列表属性选择,或者有什么解决方法?事实是,即使我返回Filechooser窗口,文件也保持选中状态,这确实很烦人。
答案 0 :(得分:0)
即使 kivy filechooser 的 selection 是只读的,您只需将选择值设置为 []
代码示例:
# import
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import Screen, ScreenManager
class SM(ScreenManager):
pass
class Screen1(Screen):
def selected(self, filename):
# displaying seleted file name as a label
self.ids.lb.text = str(filename)
class Screen2(Screen):
def deselect_action(self):
# access screen1
s1 = self.manager.get_screen('first')
# resetting file selection
s1.ids.select_file.selection = []
# kivy file
kv = Builder.load_string("""
SM:
Screen1:
Screen2:
<Screen1>:
name: 'first'
BoxLayout:
orientation: 'vertical'
FileChooserIconView:
id: select_file
on_selection: root.selected(select_file.selection)
Label:
id: lb
text: 'default'
Button:
text: 'go to second screen'
on_press:
app.root.current = 'second'
<Screen2>:
name: 'second'
Button:
text: 'go back'
on_press:
app.root.current = "first"
root.deselect_action()
""")
class filechoosing(App):
def build(self):
return kv
filechoosing().run()
在这里您可以看到,标签采用所选文件的值。返回 Filechooser 窗口屏幕时,没有选择。