Next: Configuring Subwidget Options Up: Accessing The Components Previous: Chaining the subwidget

 

Configuring Subwidget Options Using the -options Switch 

As we have seen above, we can use commands like ``subwidget name configure ...'' to set the configuration options of subwidgets. However, this can get quite tedious if we want to configure many options of many subwidgets.

There is a more convenient and terse way to configure the subwidget options without using the subwidget method: the -options switch. All Tix mega-widgets support the -option switch, which can be used during the creation of the mega-widget.

tixControl .income -label "Income: " -variable income -options {
label.width 8
label.anchor e
entry.width 10
entry.borderWidth 3
}
tixControl .age -label "Age: " -variable age -options {
label.width 8
label.anchor e
entry.width 10
entry.borderWidth 3
}
pack .income .age -side top

(Figure 1-5) Using the -options switch 


(Figure 1-6) Using the -options Switch to Align the Labels 

The use of the -options switch is illustrated in program 1-5, which creates two TixControl widgets for the user to enter his income and age. Because of the different sizes of the labels of these two widgets, if we create them haphazardly, the output may look like fig 1-6.

To avoid this problem, we set the width of the label subwidgets of the .income and .age widgets to be the same (8 characters wide) and set their -anchor option to e (flushed to right), so that the labels appear to be well-aligned. Program 1-5 also does other things such as setting the entry subwidgets to have a width of 10 characters and a border-width of 3 pixels so that they appear wider and ``deeper''. A better result is shown in figure 1-6.

As we can see from program 1-5, the value for the -options switch is a list of one or more pairs of

subwidget-option-spec value ..

subwidget-option-spec is in the form subwidget-name.option-name. For example, label.anchor identifies the anchor option of the label subwidget, entry.width identifies the width option of the entry subwidget, and so on.

Notice we must use the name of the option, not the command-line switch of the option. For example, the option that specifies the border-width of the entry subwidget has the command-line switch -borderwidth but its name is borderWidth (notice the capitalization on the name but not on the command-line switch). Therefore, we have used the capitalized version of ``entry.borderWidth 3'' in program 1-5 and not ``entry.borderwidth 3''. To find out the names of the options of the respective subwidgets, please refer to their manual pages.


http://tix.sourceforge.net