Python

[파이썬] 터미널 출력문 글꼴, 음영 색상 변경 - colorama

weweGH 2025. 3. 16. 20:25
반응형

출력문 글꼴 색상 변경
출력문 글꼴 색상 변경


터미널 출력문 글꼴, 음영 색상 변경 - colorama


  • colorama 패키지 다운로드
  • print문 글꼴 색상 변경
  • print문 글꼴 음영 색상 변경
  • print문 글꼴+음영 색상 변경

colorama 패키지


파이썬에는 print문의 색상과 음영을 변경하는 패키지인 colorama가 있습니다. colorama를 사용하면, 수많은 print문 속에서 중요한 문장들은 빨간색으로 중요 표시를 할 수 있습니다.

출력문
출력문


먼저, pip install로 colorama 패키지를 설치하고 import 합니다.

# pip install colorama # colorama download

import colorama
from colorama import Fore, Back

print문 글꼴 색상 변경


dir로 colorama에서 사용가능한 색상을 확인할 수 있습니다. 검정, 파랑, 노랑, 마젠타 등 다양한 색상으로 변경이 가능합니다.

dir(Fore)[0:10] # 색상 리스트 출력

dir(Fore)
dir(Fore) 결과


색상을 다시 원상태로 되돌릴 때는 Fore.RESET을 꼭 작성해야 합니다. 그렇지 않으면, 앞에 지정된 색상이 계속 출력됩니다.

print(Fore.BLUE + 'this is blue')
print(Fore.GREEN + 'this is green')
print(Fore.MAGENTA + 'this is magenta')
print(Fore.RED + 'this is red')
print('still red')
print(Fore.RESET + 'this is default')

colorama Fore
colorama Fore

반응형

print문 음영 색상 변경


colorama로 음영색도 변경이 가능합니다. 색상은 위의 글꼴과 동일합니다.

print(Back.BLUE + 'this is blue')
print(Back.RESET) # 초기화
print(Back.GREEN + 'this is green')
print(Back.RESET) # 초기화
print(Back.MAGENTA + 'this is magenta')
print(Back.RESET) # 초기화
print(Back.RED + 'this is red')
print(Back.RESET) # 초기화

colorama Back
colorama Back


print문 글꼴+음영 색상 변경


글꼴 색상, 음영색을 각각 변경하는 것뿐만 아니라 동시에 변경할 수도 있습니다. '+'를 활용하면 원하는 대로 변경이 가능합니다.

print(Back.RED + Fore.YELLOW +  'this is combination 1')
print(Back.GREEN + Fore.YELLOW +  'this is combination 2')
print(Back.BLUE + Fore.RED +  'this is combination 3')
print(Back.YELLOW + Fore.MAGENTA +  'this is combination 4')

colorama Back+Fore
colorama Back + Fore


이렇게 colorama를 사용하면, 중요한 문장들은 원하는 글꼴로 출력할 수 있습니다.

감사합니다
감사합니다:)

반응형