Adding and removing items from a playlist
Let's write some code for a feature that allows us to add and remove items from a playlist. To be more specific, we will write the code for a function for the four buttons marked in the following screenshot:
The four buttons, from left to right, perform the following functions:
The first button from the left adds individual audio files to a playlist
The second button deletes all the selected items from the playlist
The third button scans a directory for audio files and adds all the found audio files to the playlist
The last button empties the playlist
Since adding these features requires us to interact with the Listbox widget of Tkinter, let's spend some time getting to know the Listbox widget:
Create a Listbox widget like we'd create any other widget, as follows:
play_list = tk.ListBox(parent, **configurable options)
When you initially create a Listbox widget, it is empty. To insert one or more lines of text into the Listbox, use the
insert()
method, which...