Python Forum

Full Version: I want to be able to scroll up in curses to see previous text.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have some code that just prints the same thing over and over and its numbered but when I try scrolling up it doesn't work, But I wanna be able to scroll up using mouse scroll wheel and have like the actual scrollbar present and using keys such as pg up ect... like in a normal terminal. Now I do know curses just overlays on-top of the terminal that's why I'm wondering if there is a way to do all of this?

import curses, time
def print_hello(chat_win):
    num = 0
    while True:
        chat_win.addstr(f"Test Bot. {num} \n")
        chat_win.refresh()
        time.sleep(0.5)
        num += 1
stdscr = curses.initscr()
curses.noecho()
curses.cbreak()
stdscr.keypad(True)
curses.curs_set(0)
chat_win = curses.newwin(curses.LINES, curses.COLS, 0, 0)
chat_win.scrollok(True)
print_hello(chat_win)
Currently it just prints and whatever goes off screen at the top(previous old text) gets deleted entirety.
Thank you in advance.
So you want your program that runs in a terminal window to act like it is running in a terminal window. Why are you using curses? What am I missing?