python – 如何使用curses删除文本到行尾

前端之家收集整理的这篇文章主要介绍了python – 如何使用curses删除文本到行尾前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何删除文本到行尾?
stdscr.addstr(5,5,"Egestas Curabitur Phasellus magnis")

结果屏幕:Egestas Curabitur Phasellus magnis #OK

stdscr.addstr(5,"Elit metus")

结果屏幕:Elit metusrabitur Phasellus magnis#Problem

解决方法

删除到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.

原文链接:https://www.f2er.com/python/186193.html

猜你在找的Python相关文章