Creating menu bars
In this recipe, we will add a menu bar to our main window, add menus to the menu bar, and then add menu items to the menus.
Getting ready
We will start by learning the techniques of how to add a menu bar, several menus, and a few menu items to show the principle of how to do it. In the beginning, clicking on a menu item will have no effect. We will then add functionality to the menu items, for example, closing the main window when clicking the Exit
menu item and displaying a Help
| About
dialog.
We will continue to extend the GUI we created in the previous recipe, Aligning the GUI widgets by embedding frames within frames.
How to do it…
First, we'll have to import the Menu
class from tkinter
. Add the following line of code to the top of the Python module, where the import statements live:
Next, we will create the menu bar. Add the following code towards the bottom of the module, just above where we create the main event loop:
GUI_menubar_tearoff.py
In line 119, we are calling...