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.0.tar.gz (3.7 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.0-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cl_simple_menu-1.0.0.tar.gz
  • Upload date:
  • Size: 3.7 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.0.tar.gz
Algorithm Hash digest
SHA256 425fe496688670394434f1f0c95bfd4825ae34f33957715ba9fc2ea587967cad
MD5 41ed2ac1330a423af9bf9c591a44c07c
BLAKE2b-256 5f1375dc34d5ea49c740f0aac4f8c89d93bacaebec5488aaf4ead3e073694e80

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cl_simple_menu-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 3.2 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 051ef6b9f7eb4968560ecceb46ed6d4daa4d097a58944533638b69d5f935853d
MD5 c510581337e51a808c2487f3be336356
BLAKE2b-256 01ad98e483144c2c694bfc8ef83061c577a85bc1d8ea5e0fdb905b14ebb406d2

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