Previous section   Next section

Practical Programming in Tcl & Tk, Third Edition
By Brent B. Welch

Table of Contents
Part V.  Tk Details

Chapter 39. Fonts and Text Attributes

This chapter describes the naming conventions for fonts. Tk has a font object that you can dynamically configure and associate with widgets. This chapter also describes other text-related attributes such as justification, anchoring, and geometry gridding.

Fonts describe how characters look on the screen. Tk widgets like buttons, labels, and listboxes have a font attribute that determines which font they use to display their text. The text widget has font attributes on tags that are applied to different regions of text. Tk has a platform-independent way to name fonts (e.g., times 12 bold), plus it gracefully handles missing fonts. You can define named font objects and then associate those with widgets and text tags. When the font objects are reconfigured, the widgets using them update their display automatically. You can use the resource database to define the fonts used in your interface.

X font names (e.g., -*-times-bold-r-normal-*-12-*) were used in versions of Tk before 8.0, and the widgets would raise errors if a font could not be found. The X names have a pattern matching scheme that helps avoid some missing font errors. You can still use X font names in current versions of Tk. However, the Tk font system does not do font substitutions if you use X font names; if you use them, you must be prepared for errors. In general, you should use the platform-independent font names.

After describing fonts, the chapter explains a few of the widget attributes that relate to fonts. This includes justification, anchors, and geometry gridding.

      Previous section   Next section