【问题标题】:curses: how to find the height of written text area诅咒:如何找到书面文本区域的高度
【发布时间】:2020-08-15 14:03:12
【问题描述】:

我在curses 中创建了一个pad,然后我用一堆文本填充了它。 pad的高度是恒定的,但是我想知道pad的书写部分有多少行或它的高度。

rows, cols = std.getmaxyx()
text_win = cur.newpad(rows*3, cols)
text_win.addstr("some stuff")

【问题讨论】:

    标签: python curses python-curses


    【解决方案1】:

    您可以通过检查来自getyx 的结果来做到这一点:

    rows, cols = std.getmaxyx()
    text_win = cur.newpad(rows*3, cols)
    text_win.addstr("some stuff")
    cury, curx = text_win.getyx()
    used_rows = cury + (1 if curx == 0 else 0)
    

    由于addstr是从源头开始的,所以不需要调用getyx两次。条件表达式用于换行。

    【讨论】:

      猜你喜欢
      • 2011-06-08
      • 2018-01-21
      • 2012-12-21
      • 2020-10-21
      • 1970-01-01
      • 2016-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多