Version 8 of option

Updated 2004-04-15 18:46:12

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


The Tk command option acts on the "option database".


Chris Nelson notes:

 > I've changed to:
 > 
 >    # Why do these affect selection?
 >    option add *Entry.background red widgetDefault
 >    option add *Entry.foreground blue widgetDefault
 > 
 >    entry .e
 >    pack .e
 > 
 >    # Why is this only when the button is active?
 >    option add *Button.background red widgetDefault
 >    option add *Button.foreground green widgetDefault
 > 
 >    button .b -text Exit -command exit
 >    pack .b
 > 
 > And now the options seem to have no effect.

Based on a clue from Jeff in another conversation, I found that setting the priority to startupFile, instead of widgetDefault, was enough to get this to work. It seems Solaris' CDE does some funky color stuff.


Jeff replies:

More accurately, Solaris sets the equivalent of:

        *foreground
 and    *background

in the X defaults. Very lame way to control L&F, but that's what they chose. Those wanting to get around this can also see the solutions in the Tk Usage FAQ:

        http://www.purl.org/net/hobbs/tcl/faqs/tk/

DKF notes: For toolkits based on Xt (such as Athena, Motif and CDE) the above settings are not quite so lame. That's because the rule there is to choose the "most specific" option, and therefore those options listed above are overridden by virtually everything. It's just that Tk's option-db handling code does things quite differently...


Example of using option to allow various levels of configurability

See also http://www.man.ac.uk/~zzcgudf/tcl/option-tutorial.html and http://www.changhai.org/contents/technology/programming/tcltricks.html .


I'd like to find out what the default font for a widget is without creating the widget. It seems like option get would be the way to do this but I can't figure out exactly what I need to pass. I'm trying stuff like

  option get . *.label.font {}

and I get nothing.


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