def popping(self, button_instance):
self.small_page = Popup(title='Choose jpg or png file',size_hint=(.8,.8))
self.scroll = ScrollView()
self.small_page.add_widget(self.scroll)
file_choose = FileChooserListView()
self.scroll.add_widget(file_choose)
self.upload_pic = Button(text='Upload', size_hint=(1,.2), on_press= self.uploading(file_choose.selection))
self.small_page.add_widget(self.upload_pic)
self.small_page.open()
def uploading(self, filename):
profile_pic.source = filename[0]
i have a kivy popup window and that goes to a file chooser, everytime i try to access a file it gives the error, if possible could answer be written in python language rather than kivy.
IndexError: list index out of range
The problem is with the line:
self.upload_pic = Button(text='Upload', size_hint=(1,.2), on_press= self.uploading(file_choose.selection))
That line executes the self.uploading(file_choose.selection)
when the Button
is defined, well before you have a chance to select anything in the FileChooser
. You can use partial
to define a function to be called like this:
self.upload_pic = Button(text='Upload', size_hint=(1, .2), on_press=partial(self.uploading, file_choose))
The partial
defines a function (and its args), but does not call it. Then your self.uploading()
method can be something like:
def uploading(self, file_chooser, button):
print(file_chooser.selection[0])