Drop-Down Menus

Drop-down menus help to organize and reduce the clutter of command options.  GUI-based programs add labeled menus to a menu bar, and then add labeled command options to a menu.  In a breezypythongui application, the programmer can add menu bars with several menus each to any positions in the window’s grid.

The next code segment adds a simple File menu, with the options New, Open, and Save, to the first row in the window.


# Add the menu bar for the two menus

menuBar = self.addMenuBar(row = 0, column = 0)


# Add the File menu

fileMenu = menuBar.addMenu("File", row = 0, column = 0)


# Add the command options for the File menu

fileMenu.addMenuCommand("New",  self.newSelected)

fileMenu.addMenuCommand("Open", self.openSelected)

fileMenu.addMenuCommand("Save", self.saveSelected)



Note that the pattern for adding command options to a menu is similar to the one shown earlier for buttons.  Each menu command has a name and an event handler method associated with it.  When the user selects a name in a drop-down menu, the associated event handler method is triggered.

Here is the window for this example program (menudemo.py):