I need to show the user a part of a notebook only if he clicks on a button (or on a checkbox). For example, the user can proceed only if he answers a question correctly in the notebook! Hope to be clear in the answer, thanks to all.


One possible solution is to use the CellTag option to keep track of the cell you want to display. Here is the code:

createHiddenCell[buttonText_, cellText_] := Module[
  {cell, cellTag = ToString@Unique[], isHidden = True, modifyCell},
  cell = TextCell[cellText, CellTags -> cellTag];
  modifyCell[] := If[isHidden, CellPrint[cell],
    NotebookLocate[cellTag]; NotebookDelete[]];
   modifyCell[]; isHidden = ! isHidden


createHiddenCell["Do you like Mathematica?", "Thanks!"]

It will create a button with text "Do you like Mathematica?". And clicking it will toggle the display of your content in the second argument.

You can modify cell variable to create more complicated cell if you want.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.