使用 Rich 设置不同的背景颜色

Set different background color using Rich

我找到了有用的包 rich。并想以下一种方式使用它: 在句子和不同的背景颜色中绘制不同颜色的单词。 我使用下一个代码:

from rich.console import Console
console = Console()
console.print('[green]some[/green] [#F47983]text[/#F47983]')

这样我就可以为任何单词设置任何颜色:

但是我不知道,如何设置不同的背景颜色。我尝试了 background=bg:backgrounp-color - 这不起作用:(

用“on”这个词来介绍背景色。例如:

print(“[bold green on blue]Fear is the mind-killer[/]”)

此外,如果您想使用十六进制代码:

print('[green on #F47983]some[/] [#F47983]text[/]')

请参阅 https://rich.readthedocs.io/en/latest/style.html 了解如何定义样式。