gpt4 book ai didi

python - 如何在ncurses屏幕中移动字符串?

转载 作者:太空宇宙 更新时间:2023-11-03 18:36:13 24 4
gpt4 key购买 nike

例如,我在第一行有一个字符串“Hello world”。怎么把它移到第二行?

ps:我知道我可以使用这样的代码:

import curses

stdscr = initscr()
stdscr.adstr(x,y,"Hello World")
y += 1
stdscr.erase()
stdscr.adstr(x,y,"Hello World")
stdscr.getch()

但是我在这个“Hello World”下有很多上下文,我想找到一种仅移动或删除“Hello World”的方法。我该怎么做?

最佳答案

如果文本只占一行,您可以使用 clrtoeol函数删除从光标开始的整行:

curses.setsyx(y, 0)   # beginning of the correct line
# stdscr.move(y, 0) # alternative
stdscr.clrtoeol() # clears the current line

或者您可以使用 hline插入整行空白的函数:

stdscr.hline(y, 0, ord(' '), 80)   # where 80 is the width of the screen

关于python - 如何在ncurses屏幕中移动字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21546832/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com