How to scroll text in Python/Curses subwindow?

后端 未结 5 2017
陌清茗
陌清茗 2021-01-30 23:01

In my Python script which uses Curses, I have a subwin to which some text is assigned. Because the text length may be longer than the window size, the text should be scrollable.

5条回答
  •  南方客
    南方客 (楼主)
    2021-01-31 00:04

    OK with window.scroll it was too complicated to move the content of the window. Instead, curses.newpad did it for me.

    Create a pad:

    mypad = curses.newpad(40,60)
    mypad_pos = 0
    mypad.refresh(mypad_pos, 0, 5, 5, 10, 60)
    

    Then you can scroll by increasing/decreasing mypad_pos depending on the input from window.getch() in cmd:

    if  cmd == curses.KEY_DOWN:
        mypad_pos += 1
        mypad.refresh(mypad_pos, 0, 5, 5, 10, 60)
    elif cmd == curses.KEY_UP:
        mypad_pos -= 1
        mypad.refresh(mypad_pos, 0, 5, 5, 10, 60)
    

提交回复
热议问题