creating a sub-menu from the initial menu python notebook app

If you move the infinite loop to your main program, you can think of instantiating and presenting to the user a new (or existing) menu in every iteration, until he chooses Q(uit) from the main menu.

Then you can define a base class Menu with the basics only. After that you can think in a MainMenu sub-class, and whatever more menus you need.

The menus do not need to interact with the user, but with your program. Your program is basically a loop asking for a menu option from the user.

This isolation can be useful if you think of other ways to interact with a user or other system, and you still want to re-use these menus.

Having the menus running everything from themselves, while possible, looks a bit like menu overdesign.

You may also like the cmd module from the standard library. It is also object-oriented. You’ll have to read the documentation and follow by it’s rules though. You’ll find examples there.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top