Removing the selected files from a playlist

Since the Listbox allows for multiple selections, we iterate through all the selected items, removing them from the frontend Listbox widget as well as from the model play_list, as follows (see code 5.03view.py):

def remove_selected_files(self): try:  selected_indexes = self.list_box.curselection()  for index in reversed(selected_indexes):    self.list_box.delete(index)    self.model.remove_item_from_play_list_at_index(index) except IndexError:   pass

Note that we reverse the tuple before removing items from the playlist because we want to start removing items from the end, as a removal causes a change in the index of playlist items. If we do not remove items from the end, we may end up removing the wrong ...

Get Tkinter GUI Application Development Blueprints - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.