TTkColor🌶️

class TTkColor(fg: tuple[int] = None, bg: tuple[int] = None, mod: int = 0, colorMod=None, link: str = '', clean=False)[source]🌶️

Bases: _TTkColor

TermTk Color helper

The TTkColor constructor creates the color based on HEX values.

Example:

# Foreground only colors:
color_fg_red   = TTkColor.fg('#FF0000')
color_fg_green = TTkColor.fg('#00FF00')
color_fg_blue  = TTkColor.fg('#0000FF')

# Background only colors:
color_bg_red   = TTkColor.bg('#FF0000')
color_bg_green = TTkColor.bg('#00FF00')
color_bg_blue  = TTkColor.bg('#0000FF')

# Combine
color_1 = color_fg_red + color_bg_blue
color_2 = color_fg_red + TTkColor.bg('#FFFF00')
color_3 = color_2 + TTkColor.UNDERLINE + TTkColor.BOLD

# Use presets
color_4 = TTkColor.RED
color_5 = TTkColor.BG_YELLOW + color_4
color_6 = color_5 + TTkColor.UNDERLINE + TTkColor.BOLD

Methods🌶️

static ansi(ansi)[source]🌶️
static bg(*args, **kwargs) None[source]🌶️

Helper to generate a Background color

Example:

color_1 = TTkColor.bg('#FF0000')
color_2 = TTkColor.bg(color='#00FF00')
color_3 = TTkColor.bg('#0000FF', modifier=TTkColorGradient(increment=6))
Parameters:
  • color (str) – the color representation in (str)HEX

  • modifier (TTkColorModifier, optional) – (experimental) the color modifier to be used to improve the kinkiness

Returns:

TTkColor

static fg(*args, **kwargs) None[source]🌶️

Helper to generate a Foreground color

Example:

color_1 = TTkColor.fg('#FF0000')
color_2 = TTkColor.fg(color='#00FF00')
color_3 = TTkColor.fg('#0000FF', modifier=TTkColorGradient(increment=6))
Parameters:
  • color (str) – the color representation in (str)HEX

  • modifier (TTkColorModifier, optional) – (experimental) the color modifier to be used to improve the kinkiness

Returns:

TTkColor

static fgbg(fg: str = '', bg: str = '', link: str = '', modifier: _TTkColorModifier = None)[source]🌶️

Helper to generate a Background color

Example:

color_1 = TTkColor.fgbg('#FF0000','#0000FF')
color_2 = TTkColor.fgbg(fg='#00FF00',bg='#0000FF')
color_3 = TTkColor.fgbg('#0000FF','#0000FF', modifier=TTkColorGradient(increment=6))
Parameters:
  • fg (str) – the foreground color representation in (str)HEX

  • bg (str) – the background color representation in (str)HEX

  • modifier (TTkColorModifier, optional) – (experimental) the color modifier to be used to improve the kinkiness

Returns:

TTkColor

static hexToRGB(val)[source]🌶️

TTkColor Attributes🌶️

BG_BLACK

(bg) #000000 - Black

BG_BLUE

(bg) #0000FF - Blue

BG_CYAN

(bg) #00FFFF - Cyan

BG_GREEN

(bg) #00FF00 - Green

BG_MAGENTA

(bg) #FF00FF - Magenta

BG_RED

(bg) #FF0000 - Red

BG_WHITE

(bg) #FFFFFF - White

BG_YELLOW

(bg) #FFFF00 - Yellow

BLACK

(fg) #000000 - Black

BLINKING

"Blinking" modifier

BLUE

(fg) #0000FF - Blue

BOLD

Bold modifier

CYAN

(fg) #00FFFF - Cyan

FG_BLACK

(fg) #000000 - Black

FG_BLUE

(fg) #0000FF - Blue

FG_CYAN

(fg) #00FFFF - Cyan

FG_GREEN

(fg) #00FF00 - Green

FG_MAGENTA

(fg) #FF00FF - Magenta

FG_RED

(fg) #FF0000 - Red

FG_WHITE

(fg) #FFFFFF - White

FG_YELLOW

(fg) #FFFF00 - Yellow

GREEN

(fg) #00FF00 - Green

ITALIC

Italic modifier

MAGENTA

(fg) #FF00FF - Magenta

RED

(fg) #FF0000 - Red

RST

Reset to the default terminal color and modifiers

STRIKETROUGH

Striketrough modifier

UNDERLINE

Underline modifier

WHITE

(fg) #FFFFFF - White

YELLOW

(fg) #FFFF00 - Yellow