如何删除到行尾的文本?
stdscr.addstr(5, 5, "Egestas Curabitur Phasellus magnis")
结果屏幕:Egestas Curabitur Phasellus magnis
# OK
stdscr.addstr(5, 5, "Elit metus")
结果屏幕:Elit metusrabitur Phasellus magnis
# 问题
最佳答案
要删除到 EOL(行尾),请使用 window.clrtoeol()
:
示例:
import curses
window = curses.initscr()
window.clrtoeol()
window.refresh()
我真的推荐使用伟大的 urwid然而,对于任何控制台/TUI 编程。
更新:然而,Bhargav Rao 是对的;你必须明确地调用 window.refresh()
:
Accordingly, curses requires that you explicitly tell it to redraw windows, using the refresh() method of window objects. In practice, this doesn’t really complicate programming with curses much. Most programs go into a flurry of activity, and then pause waiting for a keypress or some other action on the part of the user. All you have to do is to be sure that the screen has been redrawn before pausing to wait for user input, by simply calling stdscr.refresh() or the refresh() method of some other relevant window.
关于python - 如何使用 curses 删除行尾的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30258647/