Configuring Subwidget Options Using the Tk Option Database<A NAME=136> </A>

Next: Caution: Restricted Access Up: Accessing The Components Previous: Configuring Subwidget Options

### Configuring Subwidget Options Using the Tk Option Database

The `-options` switch is good if you want to specify subwidget options for one or a few mega-widgets. If you want to specify the subwidget for many mega-widgets, it is easier to use the Tk Option Database.

Options in the Tk Option Database can be specified using the `option` command and the pathname of the widget. For all the Tix mega-widgets, it is guaranteed that the pathname of their subwidgets ends with the name of the subwidgets. For example, if we have a mega widget called `.a.b.megaw` and it has a subwidget whose name is `subw`, then we can be sure that the pathname of the subwidget will be something like

> `.a.b.megaw.foo.bar.subw`

Therefore, if we want to specify options for it in the Option Database, we can issue commands like:

> `option add *a.b.megaw*subw.option1 value1
> option add *a.b.megaw*subw.option2 value2`

Notice that it will be wrong to issue the commands as:

> `option add *a.b.megaw.subw.option1 value1
> option add *a.b.megaw.subw.option2 value2`

because in general we will not know whether the subwidget is an immediate child window of `.a.b.megaw` (such a decision is left to the mega-widget implementor and may vary in different versions of the same mega-widget).

Program 1-7 demonstrates how the Tk Option Database can be used to achieve the same effect as program 1-5.

> `option add *TixControl*label.width 8
> option add *TixControl*label.anchor e
> option add *TixControl*entry.width 10
> option add *TixControl*entry.borderWidth 3
> tixControl .income -label "Income: " -variable income
> tixControl .age -label "Age: " -variable age
> pack .income .age -side top`

(Figure 1-7) Using the Tk Option Database in Place of the `-options` switch