简体   繁体   中英

Curses window in Python without clearing the terminal

Is there a way to initialize curses in Python without clearing the existing text in the terminal? What I have in mind is, that when I will execute my application, it will either "push" the existing text up and executes at the bottom of the screen, or will draw itself over the existing text. I think curses' newterm function can do that, but it isn't implemented in Python. Are there any other ways?

For simple applications, eg when you just want to use colour, you can try the curses.setupterm function. The following example uses curses to print red and green text at the bottom of the screen:

import curses

curses.setupterm()

black_bg = curses.tparm(curses.tigetstr("setab"), 0)
red = curses.tparm(curses.tigetstr("setaf"), 1)
green = curses.tparm(curses.tigetstr("setaf"), 2)
white = curses.tparm(curses.tigetstr("setaf"), 7)

print black_bg+white+"This is "+red+"red"+white
print "and this is "+green+"green"+white+"."

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM