用自己的方法诅咒菜单模块

时间:2018-08-11 22:21:22

标签: python python-curses

我当前正在尝试为我的程序运行一个小的控制台菜单。 我在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作为参数被调用,它还创建输出,但由于菜单仍在菜单中,所以我无法在控制台上看到它。

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

1 个答案:

答案 0 :(得分:1)

为便于使用Python的文本用户界面库,请改用pythondialog

如果您确实想使用curses菜单扩展名,则需要花费学习时间来学习curses,因为它不容易使用。看看ncurses programming howto。它教授C语言中的ncurses编程。在学习了curses基础知识以及如何通过此howto在C中使用curses菜单扩展后,您可以将学到的知识转移到python中。

相关问题