user8038157
user8038157

Reputation:

How to get folder path with filechooser on kivy

I really searched everywhere and found a couple of answers but I don't really understand it. So I appreciate if you can help me.

I have a Filechooser and a Button inside Popup :

import...

download_path = StringProperty('')
file_chooser = FileChooserListView(dirselect = True)
btn_pop_downloader = Button(
    ...
)
content_pop_download = BoxLayout(orientation = 'vertical')
content_pop_download.add_widget(file_chooser)
content_pop_download.add_widget(btn_pop_downloader)
pop_downloader = Popup(
    ...
    content = content_pop_download
)

def get_file(self):
    download_path = self.file_chooser.path

btn_pop_downloader.bind(on_release = get_file)

The app runs and opens the Popup with the Filechooser. But when I press the Button to get the path. I get the following error:

download_path = self.file_chooser.path
AttributeError: 'Button' object has no attribute 'file_chooser'

I know the error is because the interpreter thinks self variable is the button. I need help to solve it and put the #$%&! folder path in the variable download_path

Thanks for taking the time to read.

PS: I'm pretty new. Less a month coding :)

Upvotes: 1

Views: 3304

Answers (1)

Qback
Qback

Reputation: 4908

I think that there could be error in this function:

def get_file(self):
    download_path = self.file_chooser.path

if all your code is inside some class, then get_file() should get 2 args - because when you bind function to button, then this function receive reference to this button. So first is self and second is reference to your button. So it should look like:

def get_file(self, button):
    download_path = self.file_chooser.path

But if your code is not inside any class, then it should look like:

def get_file(button):
    download_path = file_chooser.path

Upvotes: 2

Related Questions