Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit808a127

Browse files
committed
add changing text color tutorial
1 parent6613d43 commit808a127

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

‎general/printing-in-colors/colors.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
fromcoloramaimportinit,Fore,Back,Style
2+
3+
# essential for Windows environment
4+
init()
5+
# all available foreground colors
6+
FORES= [Fore.BLACK,Fore.RED,Fore.GREEN,Fore.YELLOW,Fore.BLUE,Fore.MAGENTA,Fore.CYAN,Fore.WHITE ]
7+
# all available background colors
8+
BACKS= [Back.BLACK,Back.RED,Back.GREEN,Back.YELLOW,Back.BLUE,Back.MAGENTA,Back.CYAN,Back.WHITE ]
9+
# brightness values
10+
BRIGHTNESS= [Style.DIM,Style.NORMAL,Style.BRIGHT ]
11+
12+
13+
defprint_with_color(s,color=Fore.WHITE,brightness=Style.NORMAL,**kwargs):
14+
"""Utility function wrapping the regular `print()` function
15+
but with colors and brightness"""
16+
print(f"{brightness}{color}{s}{Style.RESET_ALL}",**kwargs)
17+
18+
# printing all available foreground colors with different brightness
19+
forforeinFORES:
20+
forbrightnessinBRIGHTNESS:
21+
print_with_color("Hello world!",color=fore,brightness=brightness)
22+
23+
# printing all available foreground and background colors with different brightness
24+
forforeinFORES:
25+
forbackinBACKS:
26+
forbrightnessinBRIGHTNESS:
27+
print_with_color("A",color=back+fore,brightness=brightness,end=' ')
28+
print()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
colorama

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp