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.
Metadata
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 | Provenance | Actions |
|---|---|---|---|---|
| pyconsolemenu2-1.2.0.tar.gz | 8.0 kB | Without provenance | Details for pyconsolemenu2-1.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyconsolemenu2-1.2.0-py3-none-any.whl | Python 3 | none | any | Details for pyconsolemenu2-1.2.0-py3-none-any.whl |
Total release size: 14.7 kB
Security for PyConsoleMenu2 1.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.