0

I have this code. Can Someone help me with an If statement or any code that can call on_release event to create a new Tab.

def load_songs(self, storageLocation):
songs = []


if Path('Books').is_dir():
    for filename in storageLocation.glob('**/*.wav'):
        songs.append(filename)
        # Create  subfolder(Chapter)
    booksdir = [f for f in storageLocation.iterdir() if f.is_dir()]
    for value, Bookfolders in enumerate(booksdir):
      
         #create OneLineListItem(or Button) for each subfolder
        self.root.ids.Books.add_widget(OneLineListItem(text=str(Bookfolders), pos_hint={"center_x": 1, "center_y": 1}, ))
 

 > #Here I want a statement that would create a new Tab using the line below whenever the OneLineListItem above is clicked I also intend to close it whenever the user leaves the Tab. 

        self.root.ids.tabs.add_widget(Tab(title="yea",))
        
Wil Steve
  • 17
  • 5
  • With more research, for anyone who is interested I found using lambda solved the problem. `self.root.ids.Books.add_widget( OneLineListItem(text=str(Bookfolders), pos_hint={"center_x": 1, "center_y": 1}, on_release=lambda *args: self.root.ids.tabs.add_widget(Tab(title=f"Tab {Bookfolders}")) ))` – Wil Steve Apr 15 '21 at 10:18
  • got the cue from a question https://stackoverflow.com/questions/49265887/use-on-press-event-to-change-screen-without-kv-language-for-dynamically-created – Wil Steve Apr 15 '21 at 10:21
  • But the issue now is only the first item is working. The remaining items in the loop do not seem to be responding – Wil Steve Apr 15 '21 at 10:28

0 Answers0