Preparing our MainMenu class

Let's take a look at the following steps for preparing our MainMenu class:

  1. To begin, let's create a new file in our module called mainmenu.py.
  2. Cut the entire MainMenu class out of views.py and paste it into mainmenu.py. The first thing we'll do is change its name to explain its role more clearly:
class GenericMainMenu(tk.Menu):
  1. In order to make it easier for subclasses to build different menu structures, we're going to split all the code that creates the menu widgets into their own method. We'll call this method  _build_menu():
    def _build_menu(self):
        # The file menu
        file_menu = tk.Menu(self, tearoff=False)
        ...
  1. Move the entire __init__() method after the call to super() into this method. Each of our child ...

Get Python GUI Programming with Tkinter now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.