An extreamly easy to use Python console menu
Project description
PyConsoleMenu2
An extreamly easy to use Python console menu. (fork ver.)
Features:
- Cross platform, interactive selection
- Flexible Builder pattern
- Multi selection and Callback selection support
Preview
Installation 💾
pip install PyConsoleMenu2
Usage example 👨💻
from PyConsoleMenu2 import BaseMenu, ItemMenu, MultiMenu
# basic usage, get the index
ret = BaseMenu("title: BaseMenu").add_options(["a", "b", "c"]).run()
print(ret) # 0 / 1 / 2
# get the name, and more options
ret = (
BaseMenu("title: BaseMenu")
.add_options(["a", "b", "c"])
.add_option("d")
.default_index(1)
.prefix("[")
.suffix("]")
.raise_when_too_small()
.on_user_cancel(lambda: print("cancel"))
.run_get_item()
)
print(ret) # a / b / c / d
# multi selection (use space to select)
ret = MultiMenu("title: MultiMenu").max_count(2).add_options(["a", "b", "c"]).run()
print(ret)
# each option related to an item. could be used as callback function.
func = (
ItemMenu("title: ItemMenu")
.add_option("a", lambda: print("a"))
.add_options([("b", lambda: print("b")), ("c", lambda: print("c"))])
.run_get_item()
)
func()
Document
- Three types of menus: BaseMenu (only strings), MultiMenu (multi selections), ItemMenu (binds items to each option)
- Keybindings: See code
- methods:
run
: get index of selected option.run_get_item
: get the related item of selected option. Option string for BaseMenu, a set of string for MultiMenu, and user given item for ItemMenu.raise_when_too_small
: when set to True, raise aerror.RenderException
, otherwise ignore drawing.on_user_cancel
: exec a function when user cancel the input. If not set, raiseKeyboardInterrupt
by default.- ...
Additional
There's problem when displaying CJK string on windows terminal, caused by upstream dependency windows-curses. But still usable.
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
pyconsolemenu2-1.2.0.tar.gz
(8.0 kB
view details)