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

编程入门 行业动态 更新时间:2024-10-25 06:25:51
本文介绍了如何在python中删除一个诅咒窗口并恢复背景窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

伙计们,我正在研究 python 诅咒,我的初始窗口带有 initscr() 并且我创建了几个新窗口来重叠它,我想知道我是否可以删除这些窗口并恢复标准屏幕无需重新填充它.有办法吗?我也可以问是否有人可以告诉我窗口、子窗口、垫和子垫之间的区别.

Hell-o guys, I'm working on python curses and I have my initial window with initscr() and 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? I can also ask if someone can tell me the difference between a window, subwindow, pad and sub pad.

我有这个代码:

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.

推荐答案

这,例如,应该工作:

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 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...?

这篇关于如何在python中删除一个诅咒窗口并恢复背景窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-25 23:33:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1125437.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:窗口   背景   如何在   python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!