5

やあみんな、私は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.
4

1 に答える 1

9

これは、例えば、うまくいくはずです:

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」になります。次のキーストロークで、スクリプトは終了し、端末は通常に戻ります。これはあなたのために働いていませんか?それとも、実際に何か違うものが欲しいのですか...?

于 2010-04-04T22:20:19.770 に答える