Python Fonts and Colors

A font represents a type of displaying letters and numbers. In tkinter, fonts are mentioned using a tuple that contains font family name, size and font style as:

fnt =('Times', 40, 'bold italic underline overstrike')

Here, the font family name is 'Times' and font size is 40 pixels. If the size is a positive number, it indicates size in points. If the size is a negative number, it indicates size in pixels. The style of the font can be 'bold', 'italic', 'underline', 'overstrike'. We can mention any one or more styles as a string. The following program is useful to know the available font families in your system. All fonts are available in tkinter.font module inside tkinter module.

Fonts Available:

We should know what are the available fonts in the python, the following example prints available fonts

Python program to know the available font families.
CopiedCopy Code

from tkinter import * 
from tkinter import font 
#create root window 
root = Tk() 
#get all the supported font families 
list_fonts = list(font.families()) 
#display them 
print(list_fonts)

Colors in tkinter can be displayed directly by mentioning their names as: blue, lightblue, darkblue, red, lightred, darkred, black, white, yellow, magenta, cyan, etc. We can also specify colors using the hexadecimal numbers in the format:

#rrggbb# 8 bits per color

#rrrgggbbb# 12 bits per color

For example, #000000 represents black and #ff0000 represents red. In the same way, #000fff000 represents puregreen and #00ffff is cyan(greenplusblue).

Colors

Table gives some standard color names:

Alice Blue DeepPink1 to DeepPink4 LemonChiffon1 to LemonChiffon4 RoyalBlue
AntiqueWhite DeepSkyBlue magenta RoyalBlue1 to RoyalBlue4
AntiqueWhite1 to AntiqueWhite4 DeepSkyBlue1 to DeepSkyBlue4 magenta1 to magenta4 salmon
aquamarine DodgerBlue maroon salmon1 to salmon4
aquamarine1 to aquamarine4 DodgerBlue1 to DodgerBlue4 maroon1 to maroon4 SeaGreen
azure firebrick MistyRose SeaGreen1 to SeaGreen4
azure1 to azure4 firebrick1 to firebrick4 MistyRose1 to MistyRose4 tan
beige gold NavajoWhite tan1 to tan4
bisque gold1 to gold4 NavajoWhite1 to NavajoWhite4 thistle
bisque1 to bisque4 goldenrod OliveDrab thistle1 to thistle4
BlanchedAlmond goldenrod1 to goldenrod4 OliveDrab1 to OliveDrab4 tomato
blue gray / grey orange tomato1 to tomato4
BlueViolet gray0 to gray100 / grey0 to grey100 orange1 to orange4 turquoise
blue1 to blue4 green OrangeRed turquoise1 to turquoise4
brown green1 to green4 OrangeRed1 to OrangeRed4 VioletRed
brown1 to brown4 GreenYellow orchid VioletRed1 to VioletRed4
burlywood honeydew orchid1 to orchid4 wheat
burlywood1 to burlywood4 honeydew1 to honeydew4 PeachPuff wheat1 to wheat4
CadetBlue HotPink PeachPuff1 to PeachPuff white
CadetBlue1 to CadetBlue4 HotPink1 to HotPink4 pink yellow
chocolate InadianRed pink1 to pink4 yellow1 to yellow4
chocolate1 to chocolate2 InadianRed1 to InadianRed4 plum YellowGreen light/dark blue
coral ivory plum1 to plum4 light/dark cyan
coral1 to coral4 ivory1 to ivory4 purple light/dark goldenrod
cornsilk khaki purple1 to purple4 light/dark gray
cornsilk1 to cornsilk4 khaki1 to khaki4 red light/dark green
cyan LavenderBlush red1 to red4 light/dark grey
cyan1 to cyan4 LavenderBlush1 to LavenderBlush4 RosyBrown light/dark salmon
DeepPink LemonChiffon RosyBrown1 to RosyBrown4 light/dark seagreen