Button and Notebook Programming

Dave Withoff

Demonstrations

Standard Palettes

Pasting

Memo area in Complete Characters palette

Algebraic Manipulation palette

GettingStarted/Demos

Polyhedron Explorer

Training Materials

Slide shows

Exercises

Games

15 puzzle

Making a Palette

Use Create Table/Matrix/Palette and Generate Palette from Selection to create a palette

Mechanics

Using Create Button

Using Edit Button

Using DisplayForm

DisplayForm[
      ButtonBox["test", 
Active -> 
          True, 
ButtonEvaluator -> 
          Automatic, 
ButtonFunction  :> 
          Print["hello"]]]

Editing a cell expression

Button Options

ButtonBox["test"] // DisplayForm

Active->True

ButtonBox["test", Active -> True] // DisplayForm

ButtonStyle->"Paste"

ButtonBox["test", Active -> True, ButtonStyle -> "Paste"] // 
      DisplayForm

Pasting something other than the button contents

ButtonBox["test", Active -> True, 
        ButtonData -> "Integrate[x^2,{x,0,1}]"] // DisplayForm

Look up ButtonData in the Help Browser.

Buttons that perform operations

ButtonBox["test", 
        Active -> True, 
ButtonFunction :> 
          NotebookPut[
            Notebook[{Cell["hello world"]}, Magnification -> 10]]] // 
      DisplayForm

Specifying the evaluator

This does not work

ButtonBox["test", 
        Active -> True, 
ButtonFunction :> 
          Print["hello world"]] // DisplayForm

This does

ButtonBox["test", 
        Active -> True, 
ButtonEvaluator -> 
          Automatic, 
ButtonFunction :> 
          Print["hello world"]] // DisplayForm

Experimenting with DisplayFunction, ButtonSource, and ButtonData

\(ButtonBox["test", 
        Active -> True, 
ButtonEvaluator -> 
          Automatic, 
ButtonFunction :> \((Print[{#1, #2}] &)\)] // DisplayForm\)

\(ButtonBox["test", 
        Active -> 
          True, 
ButtonData -> "hello", 
ButtonSource -> 
          ButtonContents, 
ButtonEvaluator -> 
          Automatic, 
ButtonFunction :> \((Print[{#1, #2}] &)\)] // DisplayForm\)

Notebook Programming

Toggle buttons

({{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16}})