A customisable text driven menu system.
Project description
mdmenu
A simple and customisable text based menu system.
Installation
Install mdmenu using pip:
pip install mdmenu
Usage
A new MDMenu object can be instantiated by calling its empty constructor for a default menu or it can be called with any combination of the instance parameters. Menu items can be added and removed with .add_menu_item() and .remove_menu_item() respectively.
The appearance of the menu is customisable by setting any of the menu instance parameters
Create a default menu object
# examples/default_menu.py
from mdmenu import MDMenu
my_menu = MDMenu()
print(my_menu)
"""
################################################################################
Menu
################################################################################
1: Exit
################################################################################
"""
Create a menu with a predefined set of menu options
# examples/defined_options.py
from mdmenu import MDMenu
def hello_world():
print("Hello World!")
my_options = {
1: ("Item 1", hello_world),
2: ("Item 2", hello_world),
10: ("Item x", hello_world)
}
my_menu = MDMenu(menu_items=my_options)
print(my_menu)
"""
################################################################################
Menu
################################################################################
1: Item 1
2: Item 2
10: Item x
################################################################################
"""
Parameters
The following table list the parameters of the Menu which can be altered to customise the look and formatting of the table.
| Parameter | Description |
|---|---|
| footer_content Type: str Default: None |
A text body to be displayed in the footer of the menu, after the main body of the menu. |
| footer Type: bool Default: True |
Enabled by default, this boolean attribute indicates if the menu will be displayed with footer. |
| key_trailing_gap Type:int Default: 3 |
The number of white space to be added after the menu item key and before the items name when displaying the menu. eg. 5:<key_trailing_gap>Hello World |
| key_width Type: int Default: 7 |
The number of characters to pad the menu item key to when displayed. eg.<key_width>: Hello World |
| menu_character Type: str Default: '#' |
The character used to create borders of 'self.menu_width' for the menu |
| menu_hold_last Type: bool Default: True |
When true, the last item in the 'self.menu_items" dict is maintained as the item with the highest/last key value. As the default and most likely first item added is the exit, this provides a easy mechanism to keep it as the last last menu item even when key values are automatically assigned. |
| menu_items Type: dict[int, tuple] Default: {1: ("Exit", exit)} |
The dict of menu items in the system. Each item has a int key and a tuple with the items title and associated function. |
| menu_name Type: str Default: True |
The name of the menu as a string. The name is displayed when the attribute 'title' is true. |
| menu_width Type: int Default: 80 |
The width of the menu system |
| title_border Type: bool Default: True |
Enabled by default, this boolean attribute indicates if the menus title should be surrounded by a border of 'self.menu_character'. |
| title_padding Type: str Default: " " |
The character to use to pad the left and right of 'self.menu_name' when displayed in the menu title. |
| title_preface Type: str Default: None |
A text body to be displayed between the menu title and the main body of the menu. |
| title Type: bool Default: True |
Enabled by default, this boolean attribute indicates if the menus title should be displayed. |
Examples
Several working examples have been included and are listed in the table below
| Link | Description |
|---|---|
| examples/default_menu.py | Create an empty menu with the default formatting and implied exit menu option |
| examples/examples/defined_options.py | Create a menu with a predefined set of menu options |
| examples/examples/add_option.py | Add a menu option with a defined index key and with out and index key |
| examples/remove_option.py | Remove a menu option from the menu |
| examples/custom_formatting.py | Create menu with custom formatting |
| examples/call_function.py | Call a function selected from the menu |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters