Skip to main content

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

Selector

See other

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()

See more examples

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 a error.RenderException, otherwise ignore drawing.
    • on_user_cancel: exec a function when user cancel the input. If not set, raise KeyboardInterrupt by default.
    • ...

Additional

There's problem when displaying CJK string on windows terminal, caused by upstream dependency windows-curses. But still usable.

Project details


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)

Uploaded Source

Built Distribution

pyconsolemenu2-1.2.0-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file pyconsolemenu2-1.2.0.tar.gz.

File metadata

  • Download URL: pyconsolemenu2-1.2.0.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for pyconsolemenu2-1.2.0.tar.gz
Algorithm Hash digest
SHA256 1934cbaacb2d00bac955db85f88a1c77757613fd17b9c7ca6f8d017aac08113e
MD5 8d0ded7e8523adc7e47a0e2678f6ad8e
BLAKE2b-256 3319fe54fbf648847f8b73f067f59fcba06cc164665c3933d82edb49c4d56f3e

See more details on using hashes here.

File details

Details for the file pyconsolemenu2-1.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pyconsolemenu2-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a199a11e4f34ad75168a4590911de59f7f10fb87eb8974f766c9bdd7f5e2eef8
MD5 1065632b6d95038827c7479db3621ec9
BLAKE2b-256 579431f9d8892fddd0cbb9646d3c7858b98ed951108ca2eb6780132348afea49

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page