August 2018
Intermediate to advanced
366 pages
10h 14m
English
Provided a window, the set_menu function creates a Menu object and sets it as the window menu:
def set_menu(window, choices):
menubar = tkinter.Menu(root)
window.config(menu=menubar)
Then it populates the menu with the choices provided through the choices argument. That is expected to be a dictionary where the key is the name of the menu entry and the value is the callable that should be called when the choice is selected, or another dictionary if the choice should lead to a submenu. Finally, it supports separators when both the label and the choice are set to -.
The menu is populated by traversing the tree of options through a recursive function that calls Menu.add_command, Menu.add_cascade, and Menu.add_separator, depending ...