Version 14 of font

Updated 2003-02-27 18:57:22

http://purl.org/tcl/home/man/tcl8.4/TkCmd/font.htm


If you want background details on what a font really is, see Introduction to Fonts.


The way I understand the above doc and various writing on the subject, the font command is a way to abstract out font information. You create a font object that then can be used with your various widgets. By manipulating the font object, you can influence the fonts used in all widgets using that font object.

Does anyone have some sample code that uses the Tk option command and font objects to set various widgets?

How does one deal with language issues along with fonts - so that the user can change languages, and the appropriate fonts are used?

Are there color objects as well?


This command encapsulates a huge amount of knowledge that's difficult to locate otherwise. The newsgroup thread [L1 ] explains several key points about practices under Microsoft Windows that we'll eventually transcribe here.


Here's how to change a font to italic without having to specify it in full (e.g. if you otherwise want to use the default settings):

 button .b ;# as guinea pig for testing
 array set attributes [font actual [.b cget -font]]
 set attributes(-slant) italic
 set font [eval font create [array get attributes]] 
 .b configure -font $font 

Found by Pat Thoyts in the Tcl chatroom. I think you can even bypass the "font create" bit and directly say

 .b configure -font [array get attributes] ;# RS

KPV I think you can actually do this in one line:

    $w configure -font "[font actual [$w cget -font]] -slant italic"


A frequently-asked question: how do I specify a default menu (for example) font? The answer: use the option database, as in

    option add *Menu.font $my_preferred_font







"Practical Guide to Choosing Fonts"

"Changing all fonts in an application"

"How does one change the font in the wish widgets"

"font scaling"


Tk syntax help - Arts and crafts of Tcl-Tk programming - Category Command