List available font families in `tkinter`

In many tkinter examples available out there, you may see things like:

canvas.create_text(x, y, font=('Helvetica', 12), text='foo') 

However, this may not work when run in your computer (the result would completely ignore the font parameter). Aparently, the font parameter is ignored if there is any incorrect value in it.

In order to check if the font family is valid, how can I list all available in my system?

1

8 Answers

This question has been answered fully, but it's useful for me to be able to see what every font looks like so that I'm sure of which one I would like to use. In the interest of saving someone else from reinventing the wheel, I'll post my code here. As above, each font family is shown in a scrolling window. The difference is that each font in this code is printed in the font itself.

from tkinter import * from tkinter import font root = Tk() root.title('Font Families') fonts=list(font.families()) fonts.sort() def populate(frame): '''Put in the fonts''' listnumber = 1 for item in fonts: label = "listlabel" + str(listnumber) label = Label(frame,text=item,font=(item, 16)).pack() listnumber += 1 def onFrameConfigure(canvas): '''Reset the scroll region to encompass the inner frame''' canvas.configure(scrollregion=canvas.bbox("all")) canvas = Canvas(root, borderwidth=0, background="#ffffff") frame = Frame(canvas, background="#ffffff") vsb = Scrollbar(root, orient="vertical", command=canvas.yview) canvas.configure(yscrollcommand=vsb.set) vsb.pack(side="right", fill="y") canvas.pack(side="left", fill="both", expand=True) canvas.create_window((4,4), window=frame, anchor="nw") frame.bind("<Configure>", lambda event, canvas=canvas: onFrameConfigure(canvas)) populate(frame) root.mainloop() 

I hope this helps somebody.

0
from tkinter import Tk, font root = Tk() font.families() 
1

All The fonts Of Tkinter are:

System Terminal Fixedsys Modern Roman Script Courier MS Serif MS Sans Serif Small Fonts Bell Gothic Std Black Bell Gothic Std Light Eccentric Std Stencil Std Tekton Pro Tekton Pro Cond Tekton Pro Ext Trajan Pro Rosewood Std Regular Prestige Elite Std Poplar Std Orator Std OCR A Std Nueva Std Cond Minion Pro SmBd Minion Pro Med Minion Pro Cond Mesquite Std Lithos Pro Regular Kozuka Mincho Pro R @Kozuka Mincho Pro R Kozuka Mincho Pro M @Kozuka Mincho Pro M Kozuka Mincho Pro L @Kozuka Mincho Pro L Kozuka Mincho Pro H @Kozuka Mincho Pro H Kozuka Mincho Pro EL @Kozuka Mincho Pro EL Kozuka Mincho Pro B @Kozuka Mincho Pro B Kozuka Gothic Pro R @Kozuka Gothic Pro R Kozuka Gothic Pro M @Kozuka Gothic Pro M Kozuka Gothic Pro L @Kozuka Gothic Pro L Kozuka Gothic Pro H @Kozuka Gothic Pro H Kozuka Gothic Pro EL @Kozuka Gothic Pro EL Kozuka Gothic Pro B @Kozuka Gothic Pro B Hobo Std Giddyup Std Cooper Std Black Charlemagne Std Chaparral Pro Brush Script Std Blackoak Std Birch Std Adobe Garamond Pro Adobe Garamond Pro Bold Adobe Kaiti Std R @Adobe Kaiti Std R Adobe Heiti Std R @Adobe Heiti Std R Adobe Fangsong Std R @Adobe Fangsong Std R Adobe Caslon Pro Adobe Caslon Pro Bold Adobe Arabic Adobe Devanagari Adobe Hebrew Adobe Ming Std L @Adobe Ming Std L Adobe Myungjo Std M @Adobe Myungjo Std M Adobe Song Std L @Adobe Song Std L Kozuka Gothic Pr6N B @Kozuka Gothic Pr6N B Kozuka Gothic Pr6N EL @Kozuka Gothic Pr6N EL Kozuka Gothic Pr6N H @Kozuka Gothic Pr6N H Kozuka Gothic Pr6N L @Kozuka Gothic Pr6N L Kozuka Gothic Pr6N M @Kozuka Gothic Pr6N M Kozuka Gothic Pr6N R @Kozuka Gothic Pr6N R Kozuka Mincho Pr6N B @Kozuka Mincho Pr6N B Kozuka Mincho Pr6N EL @Kozuka Mincho Pr6N EL Kozuka Mincho Pr6N H @Kozuka Mincho Pr6N H Kozuka Mincho Pr6N L @Kozuka Mincho Pr6N L Kozuka Mincho Pr6N M @Kozuka Mincho Pr6N M Kozuka Mincho Pr6N R @Kozuka Mincho Pr6N R Letter Gothic Std Minion Pro Myriad Hebrew Myriad Pro Myriad Pro Cond Myriad Pro Light Rosewood Std Fill Marlett Arial Arabic Transparent Arial Baltic Arial CE Arial CYR Arial Greek Arial TUR Batang @Batang BatangChe @BatangChe Gungsuh @Gungsuh GungsuhChe @GungsuhChe Courier New Courier New Baltic Courier New CE Courier New CYR Courier New Greek Courier New TUR DaunPenh DokChampa Estrangelo Edessa Euphemia Gautami Vani Gulim @Gulim GulimChe @GulimChe Dotum @Dotum DotumChe @DotumChe Impact Iskoola Pota Kalinga Kartika Khmer UI Lao UI Latha Lucida Console Malgun Gothic @Malgun Gothic Mangal Meiryo @Meiryo Meiryo UI @Meiryo UI Microsoft Himalaya Microsoft JhengHei @Microsoft JhengHei Microsoft YaHei @Microsoft YaHei MingLiU @MingLiU PMingLiU @PMingLiU MingLiU_HKSCS @MingLiU_HKSCS MingLiU-ExtB @MingLiU-ExtB PMingLiU-ExtB @PMingLiU-ExtB MingLiU_HKSCS-ExtB @MingLiU_HKSCS-ExtB Mongolian Baiti MS Gothic @MS Gothic MS PGothic @MS PGothic MS UI Gothic @MS UI Gothic MS Mincho @MS Mincho MS PMincho @MS PMincho MV Boli Microsoft New Tai Lue Nyala Microsoft PhagsPa Plantagenet Cherokee Raavi Segoe Script Segoe UI Segoe UI Semibold Segoe UI Light Segoe UI Symbol Shruti SimSun @SimSun NSimSun @NSimSun SimSun-ExtB @SimSun-ExtB Sylfaen Microsoft Tai Le Times New Roman Times New Roman Baltic Times New Roman CE Times New Roman CYR Times New Roman Greek Times New Roman TUR Tunga Vrinda Shonar Bangla Microsoft Yi Baiti Tahoma Microsoft Sans Serif Angsana New Aparajita Cordia New Ebrima Gisha Kokila Leelawadee Microsoft Uighur MoolBoran Symbol Utsaah Vijaya Wingdings Andalus Arabic Typesetting Simplified Arabic Simplified Arabic Fixed Sakkal Majalla Traditional Arabic Aharoni David FrankRuehl Levenim MT Miriam Miriam Fixed Narkisim Rod FangSong @FangSong SimHei @SimHei KaiTi @KaiTi AngsanaUPC Browallia New BrowalliaUPC CordiaUPC DilleniaUPC EucrosiaUPC FreesiaUPC IrisUPC JasmineUPC KodchiangUPC LilyUPC DFKai-SB @DFKai-SB Lucida Sans Unicode Arial Black Calibri Cambria Cambria Math Candara Comic Sans MS Consolas Constantia Corbel Franklin Gothic Medium Gabriola Georgia Palatino Linotype Segoe Print Trebuchet MS Verdana Webdings Haettenschweiler MS Outlook Book Antiqua Century Gothic Bookshelf Symbol 7 MS Reference Sans Serif MS Reference Specialty Bradley Hand ITC Freestyle Script French Script MT Juice ITC Kristen ITC Lucida Handwriting Mistral Papyrus Pristina Tempus Sans ITC Garamond Monotype Corsiva Agency FB Arial Rounded MT Bold Blackadder ITC Bodoni MT Bodoni MT Black Bodoni MT Condensed Bookman Old Style Calisto MT Castellar Century Schoolbook Copperplate Gothic Bold Copperplate Gothic Light Curlz MT Edwardian Script ITC Elephant Engravers MT Eras Bold ITC Eras Demi ITC Eras Light ITC Eras Medium ITC Felix Titling Forte Franklin Gothic Book Franklin Gothic Demi Franklin Gothic Demi Cond Franklin Gothic Heavy Franklin Gothic Medium Cond Gigi Gill Sans MT Gill Sans MT Condensed Gill Sans Ultra Bold Gill Sans Ultra Bold Condensed Gill Sans MT Ext Condensed Bold Gloucester MT Extra Condensed Goudy Old Style Goudy Stout Imprint MT Shadow Lucida Sans Lucida Sans Typewriter Maiandra GD OCR A Extended Palace Script MT Perpetua Perpetua Titling MT Rage Italic Rockwell Rockwell Condensed Rockwell Extra Bold Script MT Bold Tw Cen MT Tw Cen MT Condensed Tw Cen MT Condensed Extra Bold Algerian Baskerville Old Face Bauhaus 93 Bell MT Berlin Sans FB Berlin Sans FB Demi Bernard MT Condensed Bodoni MT Poster Compressed Britannic Bold Broadway Brush Script MT Californian FB Centaur Chiller Colonna MT Cooper Black Footlight MT Light Harlow Solid Italic Harrington High Tower Text Jokerman Kunstler Script Lucida Bright Lucida Calligraphy Lucida Fax Magneto Matura MT Script Capitals Modern No. 20 Niagara Engraved Niagara Solid Old English Text MT Onyx Parchment Playbill Poor Richard Ravie Informal Roman Showcard Gothic Snap ITC Stencil Viner Hand ITC Vivaldi Vladimir Script Wide Latin Century Wingdings 2 Wingdings 3 Arial Unicode MS @Arial Unicode MS Arial Narrow Rupee Foradian Rupee DevLys 010 Calibri Light Monoton Ubuntu Medium Ubuntu Ubuntu Light Yatra One HelvLight Lato Great Vibes 
1

There are two sources of available fonts that I can think of:

  1. Font Families, and
  2. Named Fonts.
 import sys if sys.version_info.major == 3: import tkinter as tk, tkinter.font as tk_font else: import Tkinter as tk, tkFont as tk_font root = tk.Tk() print(tk_font.families()) print(tk_font.names()) 

All the available, predefined font families (like 'Courier', 'Helvetica', and numerous others) should be found in the tkFont.families() call.

Named fonts are a bit different. Whenever you create a new font instance with tkFont.Font(...), you're creating a named font, and you get back the name of the new font instance. That name will show up in the tkFont.names() list. That list comes pre-filled with all the named fonts used as defaults for different widgets. If you see a font identifier you don't recognize, like 'font1234567' or 'TkFixedFont', it's probably the name of a named font, which you can easily access and use via font = tkFont.Font(name=<fontname>).

from tkinter import * from tkinter import font root=Tk() fonts=font.families() for i in fonts: print(i) 

The snippet of code below will show a list of all the available fonts that Tkinter has to offer, using tkFont and the font.families().

from Tkinter import * import tkFont root = Tk() fonts=list(tkFont.families()) fonts.sort() display = Listbox(root) display.pack(fill=BOTH, expand=YES, side=LEFT) scroll = Scrollbar(root) scroll.pack(side=RIGHT, fill=Y, expand=NO) scroll.configure(command=display.yview) display.configure(yscrollcommand=scroll.set) for item in fonts: display.insert(END, item) root.mainloop() 
1

This is a cleaner view of all the fonts in a scroll thru window.

from tkinter import * from tkinter import font root = Tk() root.title('Font Families') fonts=list(font.families()) fonts.sort() display = Listbox(root) display.pack(fill=BOTH, expand=YES, side=LEFT) scroll = Scrollbar(root) scroll.pack(side=RIGHT, fill=Y, expand=NO) scroll.configure(command=display.yview) display.configure(yscrollcommand=scroll.set) for item in fonts: display.insert(END, item) root.mainloop() 
1

Just run this code and you will get your answer

import tkinter as tk from tkinter import Label, ttk from tkinter import font class ScrollableFrame(ttk.Frame): def __init__(self, container, *args, **kwargs): super().__init__(container, *args, **kwargs) canvas = tk.Canvas(self) scrollbar = ttk.Scrollbar(self, orient="vertical", command=canvas.yview) self.scrollable_frame = ttk.Frame(canvas) self.scrollable_frame.bind( "<Configure>", lambda e: canvas.configure( scrollregion=canvas.bbox("all") ) ) canvas.create_window((0, 0), window=self.scrollable_frame, anchor="nw") canvas.configure(yscrollcommand=scrollbar.set) canvas.pack(side="left", fill="both", expand=True) scrollbar.pack(side="right", fill="y") root = tk.Tk() fonts=list(font.families()) fonts.sort() frame = ScrollableFrame(root) for item in fonts: ttk.Label(frame.scrollable_frame,text=item,font=(item,"15")).pack() frame.pack() root.mainloop() 
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like