Button Component - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


Button Component

insert a button in a Standard Maple worksheet or document

 

Description

Component Palette Image

Button Properties

Button Component Examples

Description

• 

The button component performs an action or a series of actions to communicate with other embedded components when the button is selected, although assigning an action to a component is not required. The button component can display a caption or an image.  

• 

To perform an action when a button is clicked, select the button, and then in the Button context panel, select Edit Click Code to open the Code Editor dialog for the button. Enter the commands you want to perform in the Code Editor dialog.

• 

You need to specify one or more embedded components that will display the output of the button click. For more information, see the Button Component Examples on this page.

• 

The button component is customized by setting options in the Button context panel. To view the Button context panel, select the button component.

• 

Actions are associated with components using routines in the DocumentTools package.

• 

The Name property is used to reference the button when using the routines from the DocumentTools package.

• 

By default, the size of the button is determined from the length of the caption or the size of the selected image, in the case when you are displaying an image.  To set a specific size, click Scale to a specific size and set the width and height in pixels.  If you are displaying an image, the image is rescaled to that size.

• 

When using the Fill Color property, you should ensure that Draw border is not selected.

Component Palette Image

Button Properties

• 

The following table describes the control and use of the button component options.

  

An x in the Get column indicates that the option can be read, that is, retrieved by using the DocumentTools[GetProperty] tool.

  

An x in the Set column indicates that the option can be written, that is, set by using the DocumentTools[SetProperty] tool.

  

 

Option

Get

Set

Option Type

caption

x

x

string

code

x

x

string

enabled

x

x

true or false

fillcolor

x

x

color

fontcolor

x

x

color

image

 

x

name or string

pixelheight

x

x

positive integer

pixelwidth

x

x

positive integer

showborders

x

x

true or false

tooltip

x

x

string

type

x

 

string

usespecifiedsize

x

x

true or false

visible

x

x

true or false

  

caption 

  

The caption that appears on the button.  By default, the value is Button.

  

code 

  

The click action code that executes when the button is pressed.

  

enabled 

  

Whether a button can be clicked. If enabled is set to false, the button is grayed out and any action associated with it cannot be initiated. By default, the value is true.

  

fillcolor

  

Specifies the background color of the component. The color can be given by RGB values (a list of three integers between 0 and 255) or a string representing a color name, for example, [255,0,0] or “Red”.  When using fillcolor, ensure that showborders is false.
If not specified, the background color is white.

  

fontcolor

  

Specifies the font color of the component. The default value is [0,0,0] which corresponds to black.

  

image 

  

The image that appears on the button. If both an image and a caption are specified, the image takes precedence.

  

pixelheight 

  

When image is used, the height of the button in pixels.

  

pixelwidth 

  

When image is used, the width of the button in pixels.

  

showborders 

  

Indicates if the border of the button is shown. This only affects a button with a caption. By default, the value is true.

  

tooltip 

  

The text that appears when the user hovers the mouse over the button.

  

type 

  

The type of the component. This returns "Button".

  

usespecifiedsize 

  

Whether the specified size of the button is used. By default, the value is false.

  

visible 

  

Specifies if the button is visible. By default, the value is true.

Button Component Examples

Note: To interact with the examples provided below, open this help page as a worksheet and then execute the worksheet.

Example 1 - Display a plot of sin(x) in blue by clicking a button using embedded components.

To place the components and configure the plot component:

1. 

Insert a Plot and Button component using the Components palette. For information on displaying the Maple palettes, see the Show Palettes help page.

2. 

Click on the Plot component to display the Plot context panel on the right side of the worksheet (or document).

3. 

In the Plot Expression region, enter plot(sin(x), x=0..10);

 

The Plot component plots sin(x) in the default color (burgundy).

To display a caption on the button:

1. 

Click on the Button component to display the Button context panel.

2. 

In the Caption field, enter Blue Plot.

To edit the action of the button when it is clicked:

1. 

Click on Blue Plot, and then select Edit Click Code.

This launches the Code Editor dialog.

2. 

Before the end use; statement in the dialog, enter the following command:

SetProperty("Plot0", value, plot( sin(x), x=0..10, color=blue));

Note: Ensure the component name (that is, Plot0) is correct.

3. 

Click  on the Code Editor toolbar or from the File menu, select Save Code to accept all changes.

4. 

From the File menu, select Close Code Editor.

When you click Blue Plot, the color of the plot changes to blue.

You can verify the syntax of the embedded component action by executing the command in the worksheet.

with(DocumentTools):

SetProperty("Plot0", value,plot(sin(x), x=0..10, color = blue));

 

Example 2 - Launch the ArcLengthTutor and return the plot output in an embedded Plot component.

1. 

Insert a Plot, Label, and Button component in the worksheet.

2. 

Click the Label component to display the context panel.

3. 

In the Caption field, enter Launch the Arc Length Tutor.

4. 

Click the Button component to display the context panel.

5. 

In the Caption field, enter Run Tutor.

6. 

Click Run Tutor, and then select Edit Click Code from the context panel.

7. 

Before the end use; statement in the dialog, enter the following command:

SetProperty("Plot1", value, "Student[Calculus1][ArcLengthTutor]()");

Note: Ensure the component name matches the name of the Plot component.

8. 

Click  on the Code Editor toolbar or from the File menu, select Save Code to accept all changes.

9. 

From the File menu, select Close Code Editor.

 

  

  

 

See Also

DocumentTools

DocumentTools[GetProperty]

DocumentTools[SetProperty]

EmbeddedComponents

Maplets[Elements][Button]