Advanced Search
Mail us
Home    Manuel    Links    Faq    Submit a tcl/tk Reference    Contact Us

    Some examples tcl/tk codes     Man of Bwidget     Man of blt     mkwidget screenshots     TkOgl     Video Demo real.

  How to create a valid font name on Windows.
 You can either use X Window font names, in X Logical Font Description (XLFD) format, or a special Windows-specific format.
With Tk 8.0 or higher, you should use the font command, which allows you to create cross-platform font definitions. This is much
better than the older methods! 

If you are working with versions of Tk prior to 8.0, you need to set up XLFD font names or Windows-specific names, discussed

1. XLFD format font names 

Windows Tk will accept X font names, but you must supply all the parts (you can use a * for a wild-card, though, see below). You
can also use a number of XLFD elements, such as "bold", etc. to control the fonts. 

For example, the following all are valid font names on Tk in Windows: 

button .b1 -text "Arial" 
-font "-*-arial-bold-r-normal--*-*-*-*-*-*"
button .b2 -text "Courier" 
-font "-*-courier-medium-r-normal--*-*-*-*-*-*"
button .b3 -text "Symbol" 
-font "-*-Symbol-medium-i-normal--*-240-*-*-*-*"
pack .b1 .b2 .b3

To get the list of valid Windows font names, look in an application like Microsoft Word (or WordPad, which comes with Windows
starting with Windows 95) and check the font list. Most True Type ("TT") fonts should be scalable to a number of sizes. 

You can find out more in depth information about XLFD naming formats at 

-Eric Foster-Johnson 

2. Windows-specific font names 

In addition to the X style font names, Tk starting with version 4.2 accepts a special tuple format consisting of a 3 element list of
the form: 

{name size stylelist}

You can use any font name that Windows understands for the first element. The size is in points, and the style is a list of zero or
more items from the set of supported styles: normal, bold, medium, heavy, thin, extralight, light, semibold, extrabold, italic, oblique,
underline, strikeout. Many of these styles won`t do anything for a given font. For example, to get a 20 point TrueType Times Roman
font with bold and italic style, you would say "{Times Roman New} 20 {bold italic}". 

Note that the 3 part font specifier is just a place holder for font objects. Eventually we will support font objects that take various
configuration options and return a handle that can be used anywhere a font string is used now. 

-Scott Stanton