Skip to Content
Modern Python Standard Library Cookbook
book

Modern Python Standard Library Cookbook

by Alessandro Molina
August 2018
Intermediate to advanced
366 pages
10h 14m
English
Packt Publishing
Content preview from Modern Python Standard Library Cookbook

How it works...

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Advanced Python Development: Using Powerful Language Features in Real-World Applications

Advanced Python Development: Using Powerful Language Features in Real-World Applications

Matthew Wilkes

Publisher Resources

ISBN: 9781788830829Supplemental Content