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, raiseKeyboardInterruptby default.- ...
Additional
There's problem when displaying CJK string on windows terminal, caused by upstream dependency windows-curses. But still usable.
Release files for PyConsoleMenu2 1.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pyconsolemenu2-1.2.0.tar.gz | 8.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pyconsolemenu2-1.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.7 kB