Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1999
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1999

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Q: Can I create a button function ?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg18861] Re: Q: Can I create a button function ?
  • From: paulh at wolfram.com (P.J. Hinton)
  • Date: Sun, 25 Jul 1999 03:30:03 -0400
  • Organization: Wolfram Research, Inc.
  • References: <7n6aq7$h8v@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

In article <7n6aq7$h8v at smc.vnet.net>, xingjing at calvin.math.vt.edu (Xingjing Li) writes:

> I am trying to create a Mathematica notebook as a calculator type
> application for our project. I put some buttons such as fraction,
> square root,  integration, differentiation etc. inside the notebook
> and an editable cell which works as the work and result window. I also
> put in a "Clear" button which  I want to clear the contents in the
> editable window when I click it. But I can not find a function which
> can clear the cell but keep the original notebook open. I tried to
> write some button functions which I hope can replace the cell with
> blank cell or close the old, edited notebook then open an identical
> new notebook. But none of them worked. How can I achieve this goal by
> create my own Button Function and where should  I keep this function?

The ButtonFunction can be expressed explicitly as an option value in
the ButtonBox object itself, or you can specify a style in the style
sheet from which the button can inherit the function.  In your situation
you probably want the former.  You can probably accomplish what you want
by embedding a cell tag in the user input cell.  A call to NotebookLocate[]
can then be used to move the selection to the cell and then a NotebookWrite[]
can be used to replace the cell with a blank.

Evaluate this expression to create a cell for input entry.

Cell[TextData[""], "Input", CellFrame -> True, 
    CellTags -> "UserInput"] // CellPrint

Now evaluat this to make the button.

ButtonBox["clear input", 
    ButtonFunction :> 
      FrontEndExecute[{FrontEnd`NotebookLocate["UserInput"], 
          FrontEnd`NotebookWrite[FrontEnd`ButtonNotebook[], 
            Cell[TextData[""], "Input", CellFrame -> True, 
              CellTags -> "UserInput"]]}], ButtonEvaluator -> None, 
    Active -> True] // DisplayForm

Now enter something in the first cell you created and then press on the button
to make the cell contents disappear.

> I suspect that I can not keep it with my notebook but somewhere with
> the system files. Is there a place I can find some sample code for
> create button functions? I am using V3.0.1 on Power Mac.

See my tutorial notebook on MathSource 

http://www.mathsource.com/Content/General/Tutorials/Programming/0209-809

You may also want to review this excellent demo that is bundled with the
Mathematica online documentation.

FrontEndExecute[
  FrontEnd`HelpBrowserLookup[
    "GettingStarted",
    "CalendarMaker"
  ]
]

--
P.J. Hinton	
Mathematica Programming Group		paulh at wolfram.com
Wolfram Research, Inc.
Disclaimer: Opinions expressed herein are those of the author alone.


  • Prev by Date: Re: Help needed
  • Next by Date: Re: Re: Is there a FAQ? (Clear all)
  • Previous by thread: RE: Q: Can I create a button function ?
  • Next by thread: Problem with FourierTransform in V4