Considering the following curses console program in python. It should print the key
variable on the terminal. However, there is also a window
active so when print() invokes it really messes up the entire screen.
I would like the print to occur in a predictable place so at the end of the game I can output some results to the non-curses terminal.
What is the right way to use python print()
and curses
in single program?
import curses
screen = curses.initscr()
h, w = screen.getmaxyx()
window = curses.newwin(10, 20, 0, 0)
window.keypad(1)
curses.curs_set(0)
window.border(0)
window.timeout(100)
inputs = [];
while True:
key = window.getch()
inputs.append(key)
print(key) # <---- this messes things up
print(f"You typed: ${inputs}") # <---- this messes things up
In practice, the print() is for debug logging and other variable outputs that I need for the game.
Thank you
I tried using window.addstr() function to output the results. But I'm after how to utilise print for system output at the end of the game rather than modifying the console window.