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.1.0.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.1.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cl_simple_menu-1.1.0.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.1.0.tar.gz
Algorithm Hash digest
SHA256 5d709b28949951486e7870c4449ad77c0b36b9973662ba4df84ff4dc009c7324
MD5 f358c3816b55320490aeb985a16ab322
BLAKE2b-256 2562ccdd49675b6ab869c37f1647ccc3c34ab6c9e9f4a4ac943b199bb00f4ecf

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cl_simple_menu-1.1.0-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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 309c1ba1417faedb5df63bd9f1c44ef526f24ec2034616f5c02b7e68aa80ef96
MD5 473376942c3aebb091f37a2cca79238e
BLAKE2b-256 cfcea02e720339fd8ef28cf814b85c49b0fceaa67103da8a468a9d0569d1eaea

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