通过诅咒分别控制多个菜单

问题描述

试图弄清楚如何在两个单独的菜单之间进行切换并且有些困难。

我有2个菜单,如下所示:

# 1st Window.
def mainMenu(root,current_row,h,w):
    curses.init_pair(1,curses.COLOR_BLACK,curses.COLOR_WHITE)

    main_win = curses.newwin(h - 1,w // 2,1,1)
    main_win.border()

    main_options = ["Enter data","View data","Exit"]

    for idx,element in enumerate(main_options):
        x = 1 + idx
        y = 1

        if idx == current_row:
            main_win.attron(curses.color_pair(1))
            main_win.addstr(y,x,element)
            main_win.attroff(curses.color_pair(1))
        else:
            main_win.addstr(y,element)

    main_win.refresh()

# 2nd window.
def secondMenu(root,curses.COLOR_WHITE)

    second_win = curses.newwin(h - 1,w // 2 + 1)
    second_win.border()

    second_options = ["Option 1","Option 2","Option 3"]

    for idx,element in enumerate(second_options):
        x = 1 + idx
        y = 1

        if idx == current_row:
            second_win.attron(curses.color_pair(1))
            second_win.addstr(y,element)
            second_win.attroff(curses.color_pair(1))
        else:
            second_win.addstr(y,element)

    second_win.refresh()


def main(root):
    curses.curs_set(0)

    h,w = root.getmaxyx()

    current_row = 0

    mainMenu(root,w)

    while True:
        key = root.getch()

        if key == curses.KEY_UP and current_row > 0:
            current_row -= 1
        elif key == curses.KEY_DOWN and current_row < 2:
            current_row += 1
        elif key == ord("q"):
            break

        mainMenu(root,w)
        secondMenu(root,w)

    root.refresh()

curses.wrapper(main)

这将输出在两个窗口中都突出显示的垂直菜单。但是,当我输入时,两个菜单会同时滚动。我不太确定如何将控件隔离到一个窗口或另一个窗口。非常感谢您的帮助。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)