<p>来自<a href="http://docs.python.org/2/howto/curses.html" rel="nofollow">curses docs</a>:</p>
<blockquote>
<p>When you call a method to display or erase text, the effect doesn’t
immediately show up on the display. ...</p>
<p>Accordingly, curses requires that you explicitly tell it to redraw windows, using the <strong>refresh()</strong> method of window objects. ...</p>
</blockquote>
<p>您需要<code>screen.refresh()</code>和<code>box1.refresh()</code>以正确的顺序。</p>
<p>工作实例</p>
<pre><code>#!/usr/bin/env python
import curses
screen = curses.initscr()
try:
screen.border(0)
box1 = curses.newwin(20, 20, 5, 5)
box1.box()
screen.refresh()
box1.refresh()
screen.getch()
finally:
curses.endwin()
</code></pre>
<p>或者</p>
<pre><code>#!/usr/bin/env python
import curses
screen = curses.initscr()
try:
screen.border(0)
screen.refresh()
box1 = curses.newwin(20, 20, 5, 5)
box1.box()
box1.refresh()
screen.getch()
finally:
curses.endwin()
</code></pre>
<p>您可以使用<code>immedok(True)</code>自动刷新窗口</p>
<pre><code>#!/usr/bin/env python
import curses
screen = curses.initscr()
screen.immedok(True)
try:
screen.border(0)
box1 = curses.newwin(20, 20, 5, 5)
box1.immedok(True)
box1.box()
box1.addstr("Hello World of Curses!")
screen.getch()
finally:
curses.endwin()
</code></pre>