Search code examples
prettytable

How to set Background to black and Foreground color to white in Prettytable?


I want to display tabular data using Prettytable where the background is black and foreground is white. I cannot use the HTML option.

from prettytable import PrettyTable

tbl = PrettyTable(header_color='\033[40m')

tbl.field_names = ["col1", "col2", "Parameter", "AUC"]
tbl.add_row(["Type 1", "Vacc1", 9, 0.89])
tbl.add_row(["Type 2", "Vacc2", 7, 0.98])
tbl.add_row(["Type 3","Vacc3" ,27, 0.73])
tbl.add_row(["Type 4","Vacc4", 19, 0.72])


print('\033[40m','\033[37m',tbl)

I would like to know how we can have black background and white letters for the above table. Are there properties in prettytable that we need to use or is there some other library in conjunction with prettytable that I need to use to get the desired output.


Solution

  • Have you tried some libraries such as colorama to format the colour schema of your print's output ? Other than that, the trivial way is adding colour to your text manually.