加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

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

发布时间:2020-12-16 23:19:51 所属栏目:Python 来源:网络整理
导读:如何删除文本到行尾? stdscr.addstr(5,5,"Egestas Curabitur Phasellus magnis") 结果屏幕:Egestas Curabitur Phasellus magnis #OK stdscr.addstr(5,"Elit metus") 结果屏幕:Elit metusrabitur Phasellus magnis#Problem 解决方法 要删除到EOL(行结束),
如何删除文本到行尾?
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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读