When your application allows you to perform more than one action, a menu is frequently the most common way to allow access to those actions:
The tkinter.Menu
class allows us to create menus, submenus, actions, and separators. So, it provides everything we might need to create basic menus in our GUI-based application:
import tkinter def set_menu(window, choices): menubar = tkinter.Menu(root) window.config(menu=menubar) def _set_choices(menu, choices): for label, command in choices.items(): if isinstance(command, dict): # Submenu submenu = tkinter.Menu(menu) menu.add_cascade(label=label, menu=submenu) _set_choices(submenu, command) elif label == '-' and command == '-': # Separator menu.add_separator() else: # Simple choice menu.add_command(label=label, command=command) _set_choices...