如何在Python中删除诅咒窗口并恢复背景窗口?

发布于 2024-08-27 15:14:48 字数 501 浏览 9 评论 0原文

我正在研究 pythoncurses,并且我有一个带有 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.

I'm working on python curses and I have an initial window with initscr(). Then I create several new windows to overlap it, I want to know if I can delete these windows and restore the standard screen without having to refill it. Is there a way? Could someone tell me the difference between a window, subwindow, pad and sub pad.

I have this code:

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡写薰衣草的香 2024-09-03 15:14:48

例如,这应该有效:

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)

这会用“S”填充终端;在任何按键处,它都会用“w”填充窗口;在下一次击键时,它会删除窗口并再次显示 stdscr,所以它又是全“S”;在下一次击键时,脚本结束并且终端恢复正常。这不适合你吗?或者你真的想要一些不同的东西......?

This, e.g, should work:

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)

This fills the terminal with 'S'; at any keystoke, it fills the window with 'w'; at the next keystroke, it removes the window and show the stdscr again, so it's again all-'S'; at the next keystroke, the script ends and the terminal goes back to normal. Isn't this working for you? Or do you actually want something different...?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文