## The Default Value Model

When a new object is created, a set of options is provided by the application. Options which are not explicitly given are taken care of by the parent (the container object).

`B=gs:create(button,Win,[{x,0},{label,{text,"press Me"}}]).`

In the example shown above, the window provides default values for options like location and background color. If an application cannot use the default values provided by GS, new ones can be configured. For example, the following code creates a red button at location y=30.

`gs:config(Win,[{default,button,{y,30}}, {default,button,{font,{courier,18}}}]), B=gs:create(button,Win,[{x,0},{label,{text,"press Me"}}]).`

The syntax for the default option is {default,Objecttype,{Option,DefaultValue}}, where Objecttype is the name of any GS object. The special keywords all or buttons which denote button, radio button, and check button can be used.

The semantics for the default option can be expressed as follows: If an object of kind Objecttype is created and no value for Option is given, then use DefaultValue as the value. Only options of {Key,Value} syntax can be given a default values. Default values may be inherited in several steps. In the following example, the button will show the text "Cancel".

`gs:config(Win,[{default,button,{label,{text,"Cancel"}}}]), F=gs:create(frame,Win,[]), B=gs:create(button,F,[]).`

Default values are inherited so that changed default values only affect new objects, not existing objects.

Default values only have meaning when creating child objects, since objects which cannot have children cannot have default options. An example is buttons.

The following example illustrates how default options can be used:

Example of Default Options