# 用类 class 和 变量 自定义颜色主题

# 用类 class 和 变量 自定义颜色主题
# ---------------------------------------------------

# 一、类class
from colorama import Fore, Back, Style, init
init()
  
class Theme:  # 定义类
    error = Fore.RED  
    warning = Fore.YELLOW  
    SUCCESS = Fore.GREEN  
    RESET = Style.RESET_ALL  
  
# 使用自定义主题  
print(Theme.error + "发生错误!" + Theme.RESET)  
print(Theme.warning + "这是一个警告!" + Theme.RESET)  
print(Theme.SUCCESS + "操作成功!" + Theme.RESET)
print()

# ----------------------------------------------------

# 二、变量
from colorama import Fore, Back, Style, init
init()
#class Theme:  # 定义变量
error = Fore.RED
warning = Fore.YELLOW
success = Fore.GREEN
reset = Style.RESET_ALL

# 使用自定义主题
print(error + "发生错误!" + reset)
print(warning + "这是一个警告!" + reset)
print(success + "操作成功!" + reset)

 

posted @ 2025-06-17 03:57  nxhujiee  阅读(12)  评论(1)    收藏  举报