TIP #145: Enhanced Tk Font Handling

Title:Enhanced Tk Font Handling
Version:$Revision: 1.10 $
Author:Pat Thoyts <patthoyts at users dot sourceforge dot net>
Created:Thursday, 31 July 2003
Obsoletes:TIP #64


TIP #64 suggests some improvements to font handling under windows. However, not all of this TIP appears to have been implemented and I believe this can be done better using the Tk named fonts mechanism.


Windows, and no doubt MacOS as well, provide a number of system defined fonts. These are fonts that may be configured by the end user and that all applications are expected to use. The list includes the menu font, the caption font, the tooltip font and others. Some of the special fonts have been given symbolic names but these are not available to dynamic inspection. This TIP proposes to make these fonts available using the named font mechanism as used by the font create command. This has some significant advantages. The set of special font names becomes available to the programmer using the font names command. The font configuration is available using the font configure command. Also there is already a scheme in place to update all widgets using a named font when that fonts configuration changes. It is now a simple matter of re-defining the system fonts on receipt of the WM_SETTINGCHANGE message to have Tk properly reflect changes to the system-wide font selection.

Proposed Changes

Generic changes

The named font creation routine CreateNamedFont() is to be exposed on the public API as Tk_CreateNamedFont(). Also, the code used to delete a named font should be factored out into an API function, Tk_DeleteNamedFont().

Windows Platform-Specific Changes

A TkWinSetupSystemFonts() function is to be created which obtains the font description for the system fonts and calls Tk_CreateNamedFont() appropriately. This needs to be called during font package initialization. The fonts are obtained using the Win32 SystemParameters API and the set of defined stock object identifiers used with GetStockObject.

The toplevel Windows message message handler function WmProc must handle the WM_SETTINGCHANGE message by calling the TkWinSetupSystemFonts() function. This must call Tk_DeleteNamedFont and then Tk_CreateNamedFont to properly re-define the font and to propagate this change to all Tk widgets concerned. The Tk wigets will properly handle the font update by calling their WorldChanged procedures.

Cross-Platform Concerns

It seems likely to be useful to ensure that aliases are available for each platform for the set of system fonts. This is currently done for the Tk cursors and helps to ensure that a script written for one system will usefully operate on another platform.

Tk currently guarantees that "Courier", "Times" and "Helvetica" will always be available and are mapped to something suitable. It has been proposed that these should really be "monospace", "serif" and "sans-serif". The CSS specification [1] defines these plus "cursive" and "fantasy" but there seems no good reason to include these two names.

System Defined Fonts


The current set of special font names that Tk defines under windows are as follows, all with -underline 0 -overstrike 0 -slant roman

    ansi           -family {MS Sans Serif}  -size 8  -weight normal
    ansifixed      -family {Courier New}    -size 10 -weight normal
    defaultgui     -family {MS Shell Dlg}   -size 8  -weight normal
    device         -family System           -size 10 -weight bold
    fixed          -family {Courier New}    -size 10 -weight normal
    oemfixed       -family Terminal         -size 9  -weight normal
    system         -family System           -size 10 -weight bold
    systemfixed    -family Fixedsys         -size 9  -weight normal

These are: ansi, windows variable pitch system font; ansifixed, a monospace version of ansi; defaultgui, default GDI font for menus and dialog boxes; system, used for system.....

We can additionally provide from Windows system settings

    TkCaptionFont      -family {Trebuchet MS} -size 10 -weight bold
    TkIconFont         -family Tahoma         -size 8  -weight normal
    TkMenuFont         -family Tahoma         -size 8  -weight normal
    TkMessageFont      -family Tahoma         -size 8  -weight normal
    TkSmallCaptionFont -family Tahoma         -size 8  -weight bold
    TkStatusFont       -family Tahoma         -size 8  -weight normal

These are fairly obvious. The caption font appears in the window title bar, the icon font for desktop icons, message font for message boxes, menu font, small caption font is for toolbox-type dialogs with very thin title bars. Finally status font is the font used for tooltips and status bars. All these Tk* fonts can be changed via the Windows Desktop properties dialog.


    XmNbuttonFontList		(for pushbuttons in dialogs)
    XmNlabelFontList		(for labels)
    XmNtextFontList		(for text entry fields)
    XmNdefaultFontList		(for everything else)


Gnome or GTK+ documentation, but the Gnome 2.2 "Font Preferences" dialog lets you specify:

    Application font
    Desktop font
    Window title font
    Terminal font

It appears that all GTK+ UI controls use the same "Application" font.


KDE's font preferences dialog lists:

    Fixed Width
    Window Title


Aqua defines the following [2]:

     System font
     Emphasized system font
     Small system font
     Emphasized small system font
     Application font
     Label font
     Mini system font

The system font is used for text in menus, modeless dialogs, and titles of document windows [...] The small system font is used for informative text in alerts [...]. It is also the default font for headings in lists, for help tags, and for text in the small versions of many controls. If your application creates text documents, use the application font as the default for user-created content. The label font is used for labels with controls such as sliders and icon bevel buttons. If necessary, the mini system font can be used for utility window labels and text. Use emphasized system fonts sparingly.

An alternative reference [3] lists:


Suggested Tk Font Aliases

From all the above this TIP suggests that the following names be provided for all platforms and where possible these map to system defined fonts.


the default for all GUI items not otherwise specified.


standard fixed width font


used for menu items


used for window and dialog caption bars


used for captions on contained windows or tool dialogs.


font in use for icon captions


a font to use for tooltip windows (transient information windows)




This document is placed in the public domain.

Powered by Tcl[Index] [History] [HTML Format] [Source Format] [LaTeX Format] [Text Format] [XML Format] [*roff Format (experimental)] [RTF Format (experimental)]

TIP AutoGenerator - written by Donal K. Fellows