Skip to main content

qPyMenu

A simple terminal menu system with ANSI formatting, logging, and threaded actions.

Reference Documentation

[https://qpymenu.readthedocs.io/]

[https://pypi.org/project/qpymenu/0.6.0/]

pip install qpymenu

Features

  • Define Menus in JSON (new)
  • Nested menus and menu items
  • ANSI color and formatting support
  • Logs actions and displays them on the right side
  • Supports threaded execution of menu item actions
  • Prompts for arguments if "" is passed as args

Usage

from qpymenu import pyMenu, pyMenuItem

def test_function():
    print("Hello from test_function!")

menu = pyMenu("Example Menu")
menu.additem(pyMenuItem("Test Item", test_function))
menu.execute()

📘 Module: qpymenu.qpymenu

Class: pyMenu

pyMenu(name: str = "Main Menu")

A terminal-based menu system that supports nested menus, ANSI formatting, logging, and threaded execution of actions.

Attributes

  • name (str): The name shown at the top of the menu.
  • items (list): Menu items.
  • current_index (int): Current selection index for navigation.

Methods

additem(item: pyMenuItem)

Adds a pyMenuItem to the current menu.

  • Parameters:
    • item (pyMenuItem) – The menu item to be added.
  • Raises:
    • TypeError – If the provided item is not an instance of pyMenuItem.

addsubmenu(submenu: pyMenu)

Adds a submenu (pyMenu) to the current menu.
The submenu becomes a child of this menu, enabling nested navigation.

  • Parameters:
    • submenu (pyMenu) – The submenu instance to add.

execute()

Starts the interactive menu loop.
This method continuously displays the current menu, waits for user input, and navigates or executes based on the selection.
Input of 0 returns to the parent menu or exits if at the root level.
Logs each action and handles invalid input gracefully.


Defining Menus using JSON

example menus.json file

{
  "name": "Main Menu",
  "items": [
    {
      "type": "item",
      "name": "Say Hello",
      "action": "qpymenu.test_function",
      "args": "",
      "wait": true,
      "threaded": false
    },
    {
      "type": "submenu",
      "name": "Utilities",
      "items": [
        {
          "type": "item",
          "name": "Show Time",
          "action": "qpymenu.test_function"
        }
      ]
    }
  ]
}
@staticmethod from_json(data: dict) -> pyMenu

Creates a pyMenu instance (including nested submenus) from a JSON-like dictionary.

  • Parameters:
    • data (dict) – A dictionary representing the menu structure.
      Expected keys: name, items, where each item has type (item or submenu).
  • Returns:
    • A fully constructed pyMenu object with items and nested submenus.
  • Raises:
    • ValueError – If the input structure is invalid.

setformat(title_format: str = '\x1b[94m\x1b[1m', item_format: str = '\x1b[92m')

Sets the ANSI color format for displaying the menu title and items.

  • Parameters:
    • title_format (str) – ANSI escape string for formatting the menu title.
    • item_format (str) – ANSI escape string for formatting the menu items.

Class: pyMenuItem

pyMenuItem(name: str, action: callable = None, wait=True, args=None, threaded=False)

Represents a single menu item that can execute a callable action.

Attributes

  • name (str): Display name of the item in the menu.
  • action (callable, optional): The function to execute when selected.
  • wait (bool): If True, waits for keypress after execution.
  • args (any): Arguments to pass to the action (None, tuple, or "" to prompt).
  • threaded (bool): If True, runs the action in a new thread.

Metadata

Release files for qpymenu 0.6.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for qpymenu 0.6.2
File Size Uploaded Provenance Actions
qpymenu-0.6.2.tar.gz 8.5 kB Without provenance Details for qpymenu-0.6.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for qpymenu 0.6.2
File Interpreter ABI Platform Actions
qpymenu-0.6.2-py3-none-any.whl Python 3 none any Details for qpymenu-0.6.2-py3-none-any.whl

Total release size: 16.8 kB

Release files / qpymenu-0.6.2.tar.gz

Download URL qpymenu-0.6.2.tar.gz
Size 8.5 kB
Tags Source
SHA-256 checksum
How to use checksums
53925fee48c9c0145d7ee2e9846a3c493cc15814f5624a1a2fa8fd4db846a55d
BLAKE2b-256 checksum
How to use checksums
8dae717c27f5206c48287274c630ec62466081d60f3b63a67e262adb148ff290
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.1

Release files / qpymenu-0.6.2-py3-none-any.whl

Download URL qpymenu-0.6.2-py3-none-any.whl
Size 8.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c5050ca8de2d846d1bd1010810d00a078f6fdba67f2157204e92a4803eb54a85
BLAKE2b-256 checksum
How to use checksums
ce452be3d5fea9d5a3a485919e99a3da9b04c5d7e03f386b763cd94f3cef2bbb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.1

Security for qpymenu 0.6.2

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.

Release history Release notifications | RSS feed

This release

0.6.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page