5.1 Buttons and Actions

actions

Button widgets are similar to label widgets: they display text, bitmaps, or images. Additionally, they provide for actions: pressing the mouse button over the button widget, invokes an action. An action is either a procedure or a pair of object and message. If the action is a procedure, pressing the widget button creates a thread in which the procedure is applied. Otherwise, a thread is created that applies the object to the message provided. Actions are discussed in more detail in Section 5.6.

Figure 5.1 shows a program which creates two buttons and attaches actions to them. Pressing button B1 browses the atom pressed, whereas pressing button B2 closes the toplevel widget object T.


B1={New Tk.button tkInit(parent: W  
                         text:   'Press me!' 
                         action: proc {$}
                                    {Browse pressed}
                                 end)}
B2={New Tk.button tkInit(parent: W  
                         bitmap: error
                         action: W#tkClose)}
{Tk.send pack(B1 B2 fill:x padx:1#m pady:1#m)}

Figure 5.1: Buttons with attached actions.


action values

The action option is different from other options in that it has not a generic translation as explained in Section 3.2. Valid values for this option are not tickles, but as already mentioned, procedures or object message pairs.

Internally, an object providing for the action option, creates a Tcl script which when executed invokes the Oz procedure or object. This script is used then as value for the configuration option command. All widgets which provide for the command option in Tk, provide for the action option in Oz.

changing actions

Actions can be deleted or changed by the method tkAction. For example, deleting the action for button B1 and changing the action for B2 can be done by executing:

{B1 tkAction}
{B2 tkAction(action: B1 # tkClose)}

More information on buttons can be found in button.


Christian Schulte
Version 1.4.0 (20080702)