python - 如何使用 curses 删除行尾的文本

标签 python curses

如何删除到行尾的文本?

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/

相关文章:

javascript - Flask ajax 请求后不要重新加载网页

python - 是否可以创建 PyQt Web 应用程序?

python - 诅咒返回 AttributeError : 'module' object has no attribute 'initscr'

python - 如何删除python curses模块中的子窗口

python - 使用 PPMD​​ 压缩的 Zip 文件,以编程方式解压缩

python - vscode : How to disable auto breaking too long lines?

python - 使用猫头鹰 :Class prefix with rdflib and xml serialization

python - 刷新时在 python getstr() 中诅咒

Python:诅咒和默认的黑色

ruby - 如何在 Curses 中获取 Shift+X/Alt+X 键?