In this quick iteration, we add a contextual pop-up menu or the right-click menu with shortcuts to some common operations on the player.
For now, we will add just two functions to the right-click menu: Play and Delete.
After completion, the right-click menu will open, as shown in the following screenshot:
We have done similar contextual menus in our text editor, so we do a quick round up.
We add a new method, context_menu
, and call it from the GUI __init__
method, as follows (see Code 5.06 main-gui.py):
def create_context_menu(self): self.context_menu = Menu(self.root, tearoff=0) self.context_menu.add_command(label="Play", command=self.identify_track_to_play) self.context_menu.add_command(label="Delete", command=self.del_selected)
We also define a show_context_menu
method and bind it to right-click of mouse<<Button-3>>
from within our create_list_frame
, immediately next to where the Listbox widget...