Skip to main content

A simple cross-platform module to create pretty menu in console

Project description

python-cli-menu is a simple cross-plateform Python module that allows you to easilly create pretty custom menus in console. Customize the title, options, every colors and initial cursor position as you wish. Use arrows keys to navigate through the menu and enter key to select an option.

Quickstart

def menu(
    title: str | Sequence[str],
    options: list[str] | tuple[str, ...],
    cursor_color: str | tuple[int, int, int],
    title_color: (
        str | tuple[int, int, int] | None |
        Sequence[str | tuple[int, int, int] | None]
    ) = None,
    options_color: (
        str | tuple[int, int, int] | None |
        Sequence[str | tuple[int, int, int] | None]
    ) = None,
    initial_cursor_position: int = 0,
) -> int:

Creates a pretty menu in console with arrow key navigation and returns the index of the selected option. Clears console once an option is selected.

  • title is the main title of the menu, can be displayed on multiple lines if a list or a tuple is passed.
  • options is the list of actions or choices that can be selected.
  • cursor_color is the color of the cursor, available colors are red, green, yellow, blue, magenta, cyan, white and their lighter versions (e.g. light_red), use custom color by providing a tuple containing color RGB values.
  • title_color is the color of the title, available colors are the same as cursor_color, customize the color of each line by providing a list of colors, each color will be associated with the line of the corresponding index (default color is terminal text color).
  • options_color is the color of options, available colors are the same as cursor_color, customize every option color by providing a list of colors, each color will be associated with the option of the corresponding index (default color is terminal text color).
  • initial_cursor_position is the index of the option where the initial cursor position is set (default position is first element).

Examples :

from pythonclimenu import menu

OPTIONS = ["Option 1", "Option 2", "Option 3", "Quit"]

# Creates a simple console menu with blue cursor
menu1 = menu(title="Amazing Console Menu", options=OPTIONS, cursor_color="blue")

menu2 = menu(
    title = ["Amazing Console", "Menu"], # displays title on multiple lines
    options = OPTIONS,
    cursor_color = (255, 95, 46), # sets the cursor color using RGB values
    title_color = [
        "blue", # colors "Amazing Console"
        "light_red" # olors "Menu"
    ]
)

menu3 = menu(
    title = ["Amazing Console", "Menu"], # displays title on multiple lines
    options = OPTIONS,
    cursor_color = "yellow",
    title_color = "light_green", # colors all lines of title
    options_color = [
        "magenta", # colors options[0]
        "light_cyan", # colors options[1]
        (192, 11, 168) # colors options[2]
        # option[3] color is not specifed so it will be considered as None
    ]
    initial_cursor_position = -1 # sets cursor default position to last option
)

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

python-cli-menu-1.3.tar.gz (6.3 kB view details)

Uploaded Source

File details

Details for the file python-cli-menu-1.3.tar.gz.

File metadata

  • Download URL: python-cli-menu-1.3.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.1

File hashes

Hashes for python-cli-menu-1.3.tar.gz
Algorithm Hash digest
SHA256 0a7dcf8dd7d16c83df1894c4f63e0a509c3667d3efd55f227e1aadd20fd1ac4e
MD5 7ab212278606e51ebd555e4038576d22
BLAKE2b-256 a2e1e99add8148c2f3e8ccb95968b42ac831e2b9880ab653fd949896d8f68c98

See more details on using hashes here.

Supported by

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