Skip to main content

A lightweight Python library for interactive command-line menus.

Project description

🌟 SimpleMenu

简介 | Introduction 📖

SimpleMenu 是一个用 Python 编写的轻量级命令行菜单系统,可以通过键盘与菜单进行交互。适合用于构建交互式命令行程序。

SimpleMenu is a lightweight command-line menu system written in Python. It allows users to interact with the menu using the keyboard, making it ideal for building interactive terminal-based applications.


✨ 功能特点 | Features 🔑

  • ✅ 支持菜单选项动态添加。

  • 🎮 使用方向键 (上下键) 和回车键进行选项导航和选择。

  • 📋 支持显示选项索引。

  • 🌐 支持全局或窗口内键盘监听。

  • ⏱ 自定义键盘延迟和箭头显示符号。

  • ✅ Dynamically add menu options.

  • 🎮 Navigate and select options with arrow keys (Up/Down) and Enter key.

  • 📋 Option to display menu item indexes.

  • 🌐 Supports global or window-specific keyboard input listening.

  • ⏱ Configurable keyboard delay and arrow symbol display.


🚀 快速开始 | Quick Start

安装依赖 | Install Dependencies 📦

在命令行中安装依赖库:

Install the required libraries via the terminal:

pip install pygetwindow pywin32

使用案例 | Usage Example 💡

以下是一个包含 "Hello World" 的简单示例: Here is a simple example that includes a "Hello World" menu option:

import SimpleMenu
import time

# 定义一个选项对应的函数 | Define a function for a menu option
def HelloWorld():
    print("Hello World!")
    time.sleep(2)  # 停顿2秒观察效果 | Pause for 2 seconds to observe the output

# 创建菜单实例 | Create a menu instance
menu = SimpleMenu.SimpleMenu()

# 添加选项 | Add options
menu.addOption(" Print Hello World", HelloWorld)
menu.addOption(" Exit Menu", menu.Exit)

# 显示菜单 | Display the menu
menu.ShowMenu()

运行上述代码后,你将能够通过键盘选择并执行选项。🎉

After running the code, you can use the keyboard to navigate and execute the menu options. 🎉


🛠️ API 文档 | API Documentation 📚

SimpleMenu.__init__(hWnd=0, GlobalListen=True, ShowIndex=False)

初始化菜单系统。

  • hWnd: 窗口句柄 (默认值为 0,表示全局监听)。
  • GlobalListen: 是否启用全局键盘监听 (默认为 True)。
  • ShowIndex: 菜单项是否显示序号 (默认为 False)。

Initialize the menu system.

  • hWnd: Window handle (default is 0 for global listening).
  • GlobalListen: Enable global keyboard listening (default is True).
  • ShowIndex: Display menu item indexes (default is False).

addOption(value, func=lambda: None)

向菜单添加一个选项。

  • value: 选项的显示名称。
  • func: 选项对应的执行函数 (默认为空函数)。

Add an option to the menu.

  • value: Name of the menu option.
  • func: Function to execute when the option is selected (default is a no-op).

ShowMenu()

📜 显示菜单并开始监听用户输入。

Display the menu and start listening for user input.


Exit()

🚪 退出菜单并停止监听。

Exit the menu and stop input listening.


🎨 示例输出 | Example Output

🌟 Print Hello World <----
❌ Exit Menu

使用上下方向键移动箭头到选项上,并按下回车键执行该选项。

Use the Up and Down arrow keys to move the arrow to an option, and press Enter to execute it.


📜 许可协议 | License

您可以根据 MIT License 自由使用和修改此项目。⚖️

You are free to use and modify this project under the MIT License. ⚖️


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

cl_simple_menu-1.0.8.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cl_simple_menu-1.0.8-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file cl_simple_menu-1.0.8.tar.gz.

File metadata

  • Download URL: cl_simple_menu-1.0.8.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for cl_simple_menu-1.0.8.tar.gz
Algorithm Hash digest
SHA256 198fe15d8f3a5e8a60e5725cccf485297ee95020a633a77eb67a8cda8abd4a50
MD5 e7573d4f1beabf21512647b0f93915c0
BLAKE2b-256 4f06f9175676b9dc479133e4f4c2c04bef699eb458a688ddd493d91671caadb0

See more details on using hashes here.

File details

Details for the file cl_simple_menu-1.0.8-py3-none-any.whl.

File metadata

  • Download URL: cl_simple_menu-1.0.8-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for cl_simple_menu-1.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 b0807b1aebceb7b5309857119be07577f331b19634e6fd98d9bf3fb31df7dddf
MD5 4e7e2165ca69755037c0b3f985673b21
BLAKE2b-256 6bef52d252cf3446eeef9c0ef5f87a254927baa91905dc4c36f42dc34a746b4c

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