我对Python和Kivy还是比较陌生,这让我很难解决这个问题。该文件选择器正在运行,也可以选择多个文件,但它只会将最后选择的文件添加到列表中,而不会添加其余文件。我在做什么错了?
Py文件
class UploadWindow(Screen):
paths = StringProperty()
text_input = StringProperty()
def show_load_list(self):
content = LoadDialog(load=self.load_list, cancel=self.dismiss_popup)
self._popup = Popup(title="Load the sound files", content=content, size_hint=(.5, .5))
self._popup.open()
def load_list(self, path, filename):
with open(os.path.join(path, filename[0]), encoding="utf8", errors='ignore') as stream:
filename_actual = os.path.basename(filename.pop())
global importedfiles
importedfiles.append((filename_actual, path))
print(importedfiles)
self.dismiss_popup()
def dismiss_popup(self):
self._popup.dismiss()
class LoadDialog(FloatLayout):
load = ObjectProperty(None)
cancel = ObjectProperty(None)
Kv文件
<LoadDialog>:
BoxLayout:
size: root.size
pos: root.pos
orientation: "vertical"
FileChooserIconView:
id: filechooser
path: './'
filters: ['*.wav']
multiselect: True
BoxLayout:
size_hint_y: None
height: 30
Button:
text: "Cancel"
on_release: root.cancel()
Button:
text: "Load"
on_release:
root.load(filechooser.path, filechooser.selection)