2
$\begingroup$

I created a notebook with this line:

Grid[{{InputField[Dynamic[x]], Dynamic[x^2]}}]

Then, I filled a certain value instead of "x".

Then, I closed Mathematica and reopened it. Instead of the value I entered, I saw "x" again.

Is there a way to tell Mathematica to save all the values inside input fields with the notebook?

$\endgroup$
  • $\begingroup$ For global use or for that gui? Fir gui see DynamicModule. In general, Save and friends $\endgroup$ – Kuba Mar 22 '18 at 22:45
  • $\begingroup$ I want that, when I close Mathematica and then re-open it and re-open the same notebook, I will see the same values in the fields (like a spreadsheet) $\endgroup$ – Erel Segal-Halevi Mar 22 '18 at 23:17
  • $\begingroup$ Are you planning to use those values outside the gui or is it only supposed to work inside the gui? So have you seen DynamicModule? $\endgroup$ – Kuba Mar 23 '18 at 7:21
  • $\begingroup$ What do you mean by "outside the gui" vs "inside the gui"? I only use the notebook.. $\endgroup$ – Erel Segal-Halevi Mar 23 '18 at 10:42
  • $\begingroup$ In this context it would be the output of a Grid. But then you can evaluate x + 2 anywhere in a notebook and it will use the x from the gui as it is not scoped. The latter case is the outside. $\endgroup$ – Kuba Mar 23 '18 at 10:47
3
$\begingroup$

As @Kuba says in the comments, use DynamicModule with the SaveDefinitions->True option:

DynamicModule[{x = a},
    Grid[{{InputField[Dynamic[x]], Dynamic[x^2]}}],
    SaveDefinitions->True
]
$\endgroup$
  • 1
    $\begingroup$ x will be saved by default, unless UnsavedVariables is used. SaveDefinitions afects symbols that are not scoped by DynamicModule but used inside inner Dynamics. $\endgroup$ – Kuba Sep 29 '18 at 21:08

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.