【问题标题】:Curses menu module with own methods用自己的方法诅咒菜单模块
【发布时间】:2018-08-11 22:21:21
【问题描述】:

我目前正在尝试为我的程序运行一个小型控制台菜单。 我在 PyPi curses-menu 上找到了 curses-menu 模块并尝试了运气。

curses 菜单有一个 FunctionItem 调用 python 函数,但遗憾的是我在控制台上看不到输出。这是我的示例代码:

# Import the necessary packages
from cursesmenu import *
from cursesmenu.items import *

def hello(x):
    print("Hello {}".format(x))

# Create the menu
menu = CursesMenu("Title", "Subtitle")

# Create some items

# A FunctionItem runs a Python function when selected
function_item = FunctionItem("Call a Python function", hello, [3])

# Once we're done creating them, we just add the items to the menu
menu.append_item(function_item)

# Finally, we call show to show the menu and allow the user to interact
menu.show()

hello3 作为参数调用,它还创建输出,但我在控制台上看不到它,因为菜单仍然存在。

遗憾的是,我现在不知道该怎么办。如果有人能帮助我解决这个问题或告诉我一个更好的控制台菜单模块,我会很高兴。

【问题讨论】:

    标签: python python-curses


    【解决方案1】:

    如需更易于使用的 Python 文本用户界面库,请查看 pythondialog

    如果你真的想改用curses菜单扩展,你需要投入学习时间来学习curses,因为它不好用。看看ncurses programming howto。它教授 C 语言中的 ncurses 编程。在学习了 curses 基础知识以及如何从这个 howto 中使用 C 中的 curses 菜单扩展之后,您可以将所学的知识转移到 python 中。

    【讨论】:

    • 谢谢,我会看看 pythondialog。 Curses 只是第一个说服我尝试的模块。
    猜你喜欢
    • 1970-01-01
    • 2018-12-18
    • 2020-03-25
    • 1970-01-01
    • 1970-01-01
    • 2014-03-24
    • 2010-11-21
    • 2012-04-08
    • 2014-04-23
    相关资源
    最近更新 更多