I have a function that creates buttons based on subfolders in a folder. It creates a button per subfolder, and gives it the name of the subfolder.
When pressed, I want the button to open another function and to pass that function its name.
def _sidepanel(self):
    curdir = "/Users/xxx/Desktop/Test/"
    layout = BoxLayout(orientation="vertical", pos_hint={"x": 0.0, "y": 0.0}, size_hint=(0.1,1))
    for folders in glob(join(curdir, "*")):
        name = basename(folders)
        btn = Button(text=name, on_press=lambda x: self._printname(name))
        layout.add_widget(btn)
    return layout
def _printname(self, name):
    print(name)
I have 5 subfolders, and I would expect a button to print its specific name, but instead they all print the name of the last folder run by the first function.
 
    