Skip to main content

Python Console Menu

license

This library provides a way to quickly create the menu for your Python console app.

Overview

Classes

AbstractMenu

This is the abstract class you need to extend in your menus. Its constructor takes in a title which is displayed at the top of the menu. This should be called from your implementation's constructor. Like so:

class MenuImplementation(AbstractMenu):
    def __init__(self):
        super().__init__("Menu Title")
Methods
  • initialise() this needs overriding in your implementations and is where you add the items to the menu.
  • display() this starts this menu. This only needs to be called on the root menu in your system, as all sub-menus are handled by this library.
  • add_menu_item(MenuItem(id, description, subMenu or action)) this adds an item to the menu.
  • add_hidden_menu_item(new MenuItem(id, description, subMenu or action)) this is a helper method that adds a menu item, which is then hidden.
  • update_menu_items() this can be overridden per menu to update items based on changes to your application, such as showing hidden menu items if they're now needed.
  • show_menu_item(id) this can be used to show hidden menu items, most commonly in the method above. This uses the unique id given to the menu item.
  • hide_menu_item(id) this can be used to hide menu items.

MenuItem

This is the class used to define items for the menus in your system. It has two constructors one for if the item is a sub menu and another for if its an action. These should be called like this: MenuItem(id, description, subMenu or action)

Methods
  • hide() which is used on menu items, to hide them from the list.
  • show() which is used on hidden menu items, to show them in the list.
  • set_as_exit_option() which is used to set menu items as the exit option for a menu, either going to the parent menu, or exiting the application.

Example

Menu initialisation

mainMenu = MainMenu()
mainMenu.display()

Main Menu Class

class MainMenu(AbstractMenu):
    def __init__(self):
        super().__init__("Welcome to the main menu")

    def initialise(self):
        self.add_menu_item(MenuItem(100, "Exit menu").set_as_exit_option())
        self.add_menu_item(MenuItem(101, "Print Hello World", lambda: print("Hello World!")))

Output

Welcome to the main menu
0. Exit menu
1. Print Hello World
Select option: 1
Hello World!

Welcome to the main menu
0. Exit menu
1. Print Hello World
Select option: 0

Process finished with exit code 0

Look in demo/menu_demo.py for a better example implementation of the library.

Release files for python-console-menu 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-console-menu 1.1.0
File Size Uploaded
python_console_menu-1.1.0.tar.gz 3.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for python-console-menu 1.1.0
File Interpreter ABI Platform
python_console_menu-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 11.2 kB

Release files / python_console_menu-1.1.0.tar.gz

Download URL python_console_menu-1.1.0.tar.gz
Size 3.3 kB
Tags Source
SHA-256 checksum
How to use checksums
439ea6611c10fb166e75aad8ede6407110d2e96862b149d398e62a28742a8be3
BLAKE2b-256 checksum
How to use checksums
c4290273bd13fc2e9c2fbc682d753a450394725e1e6d5eb22aa449a98dbbfe13
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

Release files / python_console_menu-1.1.0-py3-none-any.whl

Download URL python_console_menu-1.1.0-py3-none-any.whl
Size 7.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ef6b00b053cb4ee27f963cfffc274370eab3d4b80fda761aa03b0b3e45ee089f
BLAKE2b-256 checksum
How to use checksums
7e6845e0fd13178d0b1aa33d06b6c2ac2e3f60649fbadcb6a3a91753bf5ad1e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page