API¶
-
class
pytabby.
Menu
(config, start_tab_number=0)[source]¶ Base class to import to create a menu
- Parameters
config (dict) – a nested dict, in a schema which will be validated, containing everything needed to instantiate the Menu class
start_tab_number (int) – default 0, the number of the tab to start at
-
run
(message=None)[source]¶ Displays menu at currently selected tab, asks for user input and returns it as a string
Examples
>>> config = Menu.safe_read_yaml('config.yaml') >>> menu = Menu(config, start_tab_number=0) >>> result = menu.run() >>> if result = "action name": >>> my_great_function()
>>> # with a submenu >>> config = Menu.safe_read_yaml('config.yaml') >>> menu = Menu(config, start_tab_number=0) >>> result = menu.run() >>> if result = "further options": >>> submenu = Menu(submenu_config) >>> if submenu_result = "action name": >>> my_great_function()