Version 9 of font

Updated 2002-05-16 13:33:47

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


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 which 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?as


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 which 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


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














































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