Zlo*_*niy 2 python curses window
地狱男人,我正在研究python curses,我的初始窗口有initscr(),我创建了几个新的窗口来重叠它,我想知道我是否可以删除这些窗口并恢复标准屏幕而不必补充它.有办法吗?我也可以问一下是否有人可以告诉我窗口,子窗口,垫和子垫之间的区别.
我有这个代码:
stdscr = curses.initscr()
####Then I fill it with random letters
stdscr.refresh()
newwin=curses.newwin(10,20,5,5)
newwin.touchwin()
newwin.refresh()
####I want to delete newwin here so that if I write stdscr.refresh() newwin won't appear
stdscr.touchwin()
stdscr.refresh()
####And here it should appear as if no window was created.
Run Code Online (Sandbox Code Playgroud)
例如,这应该工作:
import curses
def fillwin(w, c):
y, x = w.getmaxyx()
s = c * (x - 1)
for l in range(y):
w.addstr(l, 0, s)
def main(stdscr):
fillwin(stdscr, 'S')
stdscr.refresh()
stdscr.getch()
newwin=curses.newwin(10,20,5,5)
fillwin(newwin, 'w')
newwin.touchwin()
newwin.refresh()
newwin.getch()
del newwin
stdscr.touchwin()
stdscr.refresh()
stdscr.getch()
curses.wrapper(main)
Run Code Online (Sandbox Code Playgroud)
这使终端充满'S'; 在任何一个keystoke,它用'w'填充窗口; 在下一次击键时,它会移除窗口并再次显示stdscr,所以它再次全部为'''; 在下一次击键时,脚本结束,终端恢复正常.这不适合你吗?或者你真的想要一些不同的东西......?