擅长:python、mysql、java
<p>这似乎是一个XY问题。您并不真正希望使用线程同时运行多行代码。要构建复杂的全屏终端应用程序,您应该看看<a href="https://docs.python.org/3/howto/curses.html" rel="nofollow noreferrer">^{<cd1>}</a>:</p>
<pre><code>import curses
def getname(stdscr):
stdscr.clear()
stdscr.addstr(0, 0, "+---------------------------+")
stdscr.addstr(1, 0, "What is your name adventurer?")
stdscr.addstr(2, 0, "> ")
stdscr.addstr(3, 0, "+---------------------------+")
curses.echo()
return stdscr.getstr(2, 3, 20)
s = curses.wrapper(getname)
print("Name is", s)
</code></pre>
<p>这只要求输入名称,然后返回,但您也可以添加行,或替换现有屏幕上的现有行并刷新屏幕</p>