簡體   English   中英

用Python修復窗口而不清除終端

[英]Curses window in Python without clearing the terminal

有沒有辦法在Python中初始化curses而不清除終端中的現有文本? 我的想法是,當我執行我的應用程序時,它將“推”現有文本並在屏幕底部執行,或者將自己繪制在現有文本上。 我認為curses的newterm函數可以做到這一點,但它沒有在Python中實現。 還有其他方法嗎?

對於簡單的應用程序,例如,當您只想使用顏色時,可以嘗試使用curses.setupterm函數。 以下示例使用curses在屏幕底部打印紅色和綠色文本:

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+"."

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM