The Mathematica Journal
Departments
Download This Issue
Home
Feature Articles
Graphics Gallery
Tricks of the Trade
In and Out
Columns
The Mathematica Programmer
New Products
New Publications
Classifieds
Calendar
News Bulletins
Editor's Pick
Mailbox
Letters
Write Us
About the Journal
Staff and Contributors
Submissions
Subscriptions
Advertising
Back Issues

Buttons with Graphics

Dale Horton

A new feature for Mathematica 4 is the ability to put any Cell expression on the face of a button. This means that anything you can create in a cell (such as graphics) can appear on your buttons.

[Graphics:../Images/index_gr_1.gif]
[Graphics:../Images/index_gr_2.gif]

[Graphics:../Images/index_gr_3.gif]

To put this graph on the button, you first need to know how to generate the Cell expression for the graph. This is done with the DisplayString command.

[Graphics:../Images/index_gr_4.gif]
[Graphics:../Images/index_gr_5.gif]

This string is placed inside a Cell expression. The first argument of Cell indicates that the cell is PostScript GraphicsData. The second argument is the cell style Graphics. Additional arguments are Cell options.

[Graphics:../Images/index_gr_6.gif]
[Graphics:../Images/index_gr_7.gif]

This cell is embedded in another cell which creates the button. The first argument is the ButtonBox. The first argument of the ButtonBox is the graphics cell. The rest are options of the button. The second argument, again, is the cell style of the button cell. Additional arguments are any options of the button cell, including the action of the button (e.g., myfunction).

[Graphics:../Images/index_gr_8.gif]
[Graphics:../Images/index_gr_9.gif]

Now that we have all the parts, we can write the cell to the front end with DisplayForm, NotebookWrite, or CellPrint.

[Graphics:../Images/index_gr_10.gif]
[Graphics:../Images/index_gr_11.gif]

We then can apply this function to any graphics. (DisplayFunction->Identity suppresses the normally generated graphics.)

[Graphics:../Images/index_gr_12.gif]
[Graphics:../Images/index_gr_13.gif]

The same can be done by using the DisplayFunction option when generating graphics.

[Graphics:../Images/index_gr_14.gif]
[Graphics:../Images/index_gr_15.gif]

Clicking on either of the above buttons will create a new notebook with an animated moebius strip.


Converted by Mathematica      October 8, 1999

[Next Page]