O'Reilly logo

Python GUI Programming with Tkinter by Alan D. Moore

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required