3

Where can I find a list of all the fonts that tkinter supports? I checked the source code of tkinter but I didn't find it. I see one(http://www.tcl.tk/man/tcl8.6/TkCmd/colors.htm) that has all colors but I didn't find one for fonts.

Nae
  • 14,209
  • 7
  • 52
  • 79
Seaky Lone
  • 992
  • 1
  • 10
  • 29

2 Answers2

4

This outputs tkinter font names.

from tkinter import Tk
import tkinter.font
Tk()
for name in sorted(tkinter.font.families()):
    print(name)
michael_heath
  • 5,262
  • 2
  • 12
  • 22
0

I have this program that will print the font names on console if you enter it from the command line. it is python 2.7 but easy to change for 3.x. There is a little side effect that it opens a blank window - just ignore it. I have windows 10.

# show-tk-fonts.py
# Sunday, December 10, 2017      4:45:00 PM     -0600

import datetime
import sys
from   Tkinter import Tk
import tkFont

def mysort(a,b):
    if a[0] == '@':
        a = a[1:]
    if b[0] == '@':
        b = b[1:]
    return cmp(a.lower(), b.lower())

root = Tk()
print "# show-tk-fonts.py output"
print "#", datetime.datetime.now()
print
i    = 0
max  = 1
nam  = ""
fnames = list(tkFont.families())
fnames.sort(mysort)
for s in fnames:
    if len(s) > max:
        max = len(s)
        nam = s
    ls = 32-len(s)
    if i == 0:
        sys.stdout.write('    "'+s+'"'+' '*ls)
    else:
        sys.stdout.write('"'+s+'"'+' '*ls)
    i += 1
    if i == 3:
        sys.stdout.write('\n')
        i = 0
#print "max length = ",max
#print "name       = ",'"'+nam+'"'
print "normal exit"
root.mainloop()
Marichyasana
  • 2,966
  • 1
  • 19
  • 20