C.1. The Font String

When there is a -font option for a widget, you need to pass a string that indicates which font to use. There are several ways to specify a font string:

  • Specify the name of a font with the fontCreate method (fontCreateis explained later in this chapter in "Font Methods").

  • Use a string that describes the font and follows a predefined format (see Appendix B); for example, "Times 12 Normal."

  • Use the name of a font that can be interpreted by the graphics display (typically a Unix system running X Windows). These strings usually have asterisks in them and are very hard for humans to comprehend.

To specify a font in a string, you first have to know which fonts are available on your system.

C.1.1. Determining Available Fonts

In Unix, you must specify fonts by using a long, drawn-out syntax with a lot of asterisks that represent families, size, type, and so on. In the X Window System, you can get a list of Unix fonts by running the command

xlsfonts > font_file

The filenamed font_file will now contain a huge list of fonts that you can use on your system. Be careful when picking fonts from this huge list. If you are going to be running your application from more than one system, the font you pick might not be available on all systems.

If you use Microsoft Windows, you'll have a different way of seeing what fonts are available. Click on the Start menu and select Settings → Control Panel. Once the Control Panel appears, double-click Fonts and a window similar to the one ...

Get Learning Perl/Tk now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.