Skip to content
Advertisement

Call variable from a loop in another method

How do I call Bookfolders in remove_tab?

class Main(MDApp):


    def build(self):
        return


    def remove_tab(self, *args):
        #if len(self.root.ids.tabs.get_tab_list()) >0:
        self.root.ids.tabs.remove_widget(Tab(title=(Bookfolders)) #get bookfolders
        self.root.ids.tabs.clear_widgets(self.root.ids.tabs.get_tab_list())

        
    def load_songs(self, storageLocation):
        songs = []
        #  dictionary = {}

        if Path('Books').is_dir():
            for filename in storageLocation.glob('**/*.wav'):
                songs.append(filename)
                # Create dictionary for each subfolder(Chapter)
            booksdir = [f for f in storageLocation.iterdir() if f.is_dir()]
            # for value, Bookfolders in enumerate(booksdir):
            for Bookfolders in booksdir:
                # if Bookfolders not in dictionary:
                # dictionary[Bookfolders] = []
                # dictionary[Bookfolders].append('yahoooooo')

Advertisement

Answer

Just make Bookfolders an instance field like so

class Main(MDApp):
    def load_songs(self):
        ...
        self.Bookfolders = ...

Then you can access that data in any method.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement