python colorama模塊


python colorama模塊

 

colorama是一個python專門用來在控制台、命令行輸出彩色文字的模塊,可以跨平台使用。

1. 安裝colorama模塊

1
pip install colorama

  

可用格式常數:

1
2
3
Fore: BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, RESET.
Back: BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, RESET.
Style: DIM, NORMAL, BRIGHT, RESET_ALL

  

跨平台印刷彩色文本可以使用彩色光的常數簡稱ANSI轉義序列:

1
2
3
4
5
6
from  colorama  import  Fore,Back,Style
print  (Fore.RED  +  "some red text" )
print  (Back.GREEN  +  "and with a green background" )
print  (Style.DIM  +  "and in dim text" )
print  (Style.RESET_ALL)
print  ( "back to normal now!!" )

  


Init關鍵字參數:
init()接受一些* * kwargs覆蓋缺省行為

1
init(autoreset  =  False ):

  


如果你發現自己一再發送重置序列結束時關閉顏色變化每一個打印,然后init(autoreset = True)將自動化
示例:

1
2
3
4
from  colorama  import  init,Fore
init(autoreset = True )
print  (Fore.RED  +  "welcome to python !!" )
print  ( "automatically back to default color again" )


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM