Introduction
Containers Layouts Widgets Miscellaneous

Widgets -> button

To create a button, use the following syntax:

$buttonName = button('Label' [, properties]);

Label refers to a string or text that will appear in the button. See table below for the list of properties.

Here is an example of buttons.

The snippet below shows how the above demo was created.

alias buttondemo {
   # Create the main frame
   $bframe = frame('Button Demo', 'size=310 220');

   # 'Extract' the existing default panel from the frame
   $fpanel = panel($bframe, 'layout=flow');

   # Create the buttons
   $b1 = button('Simple button');
   $b2 = button('Button with icon', 'icon=icons/error.png');
   $b3 = button('Button with custom font', 'font=14 Courier', 'fontstyle=BOLD ITALIC');
   $b4 = button('Different color', 'bgcolor=GREEN');

   # Add the buttons to the panel
   addWidget($fpanel, $b1);
   addWidget($fpanel, $b2);
   addWidget($fpanel, $b3);
   addWidget($fpanel, $b4);

   show($bframe);
}

Hint: It is possible to use HTML tags as the button label/text. However, it is limited to HTML 3.2 only. Below is an example:

$b = button('<html><p>This is a button with<br>two lines of text</p></html>');

Properties

NameArgumentsDescExample
size w h W and H means width and height of the button. $b = button('Text', 'size=175 25');
icon filename This specifies the icon that will be shown in the button. $b = button('Different icon', 'icon=somefile.png');
command subroutine name This specifies the subroutine that will be performed when the button is clicked. Make sure the subroutine name must be prefixed with a &. $b = button('Text','command=&SomeSub');
tooltip text This specifies the tooltip text when the mouse is hovered over the button. $b = button('Text', 'tooltip=Lorem ipsum whatever');
state 1 or 0 Specifies the initial state of the button. 1 is enabled (also the default), and 0 is disabled. $b = button('Text', 'state=0');
fgcolor COLOR Specifies the foreground color, or the color of the text in that button. $b = button('Text', 'fgcolor=GREEN');
bgcolor COLOR Specifies the background color of the button. $b = button('Text', 'bgcolor=GRAY');
font fontsize fontname This specifies the font of the button label. A font size MUST be specified along with the font name. $b = button('Text', 'font=14 Verdana');
fontstyle BOLD, ITALIC or NORMAL This specifies the font style of the button label. This MUST be used with the font property above. $b = button('Text', 'font=14 Verdana', 'fontstyle=BOLD');
bounds x y w h .. ..

These properties are optional and can be in any order.

Related commands and functions

enable($button)Self-explanatory.
disable($button)Self-explanatory.
- End of page -
Hosted by www.Geocities.ws

1