我需要一个使用python中的面板重叠curses窗口的示例

时间:2014-01-16 20:22:53

标签: python curses python-curses

我正在寻找一个关于如何使用curses.panel维护重叠窗口的示例。

1 个答案:

答案 0 :(得分:8)

我在这里发现了这个https://mail.python.org/pipermail/python-list/2001-April/105015.html。它在屏幕上移动一个面板,在另一个面板下方。

from time import sleep
import curses, curses.panel

def make_panel(h,l, y,x, str):
 win = curses.newwin(h,l, y,x)
 win.erase()
 win.box()
 win.addstr(2, 2, str)

 panel = curses.panel.new_panel(win)
 return win, panel

def test(stdscr):
 try:
  curses.curs_set(0)
 except:
  pass
 stdscr.box()
 stdscr.addstr(2, 2, "panels everywhere")
 win1, panel1 = make_panel(10,12, 5,5, "Panel 1")
 win2, panel2 = make_panel(10,12, 8,8, "Panel 2")
 curses.panel.update_panels(); stdscr.refresh()
 sleep(1)

 panel1.top(); curses.panel.update_panels(); stdscr.refresh()
 sleep(1)

 for i in range(20):
  panel2.move(8, 8+i)
  curses.panel.update_panels(); stdscr.refresh()
  sleep(0.1)

 sleep(1)

if __name__ == '__main__':
 curses.wrapper(test)