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

2024-10-03 11:26:01 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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()

使用hello作为参数调用3,它也创建了输出,但是我在控制台上看不到它,因为菜单还在那里。在

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


Tags: 模块thetofromhelloshow菜单items
1条回答
网友
1楼 · 发布于 2024-10-03 11:26:01

要获得一个更易于使用的python文本用户界面库,请看一下pythondialog。在

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

相关问题 更多 >