During the development of my code I need to change a variable repeatedly to see what the resulting effect is and find out that the code works as expected. However, it is hard to scroll down and up to find that variable and change its value.

When someone clicks on Evaluation menu and then Debugger a small window appears. I would like such a small window for the variable I want to change that is there is always a small windows say on the upper right of Mathematica which I can enter the value of a variable and change its value inside the code I have written.

Is it possible to do such a thing at all?

  • 2
    $\begingroup$ CreatePalette @ Dynamic @ x? $\endgroup$
    – Kuba
    Feb 9, 2015 at 14:55

1 Answer 1

CreatePalette[InputField[Dynamic@x], WindowClickSelect -> True]


As reported by @AlexeiBoulbitch (see comments), this solution seems not to work for Windows OS (it does work for me on OS X, v10.0.2). I actually found a duplicate post which already mention the problem 3 years ago ... This post also gives the following workaround :

CreatePalette[InputField[Dynamic@x], WindowClickSelect -> True, WindowFloating -> False]

which unfortunately makes the palette not really useful, as it can be now hidden by any other notebook ...


1. Floating Notebook

I tried here to create a floating notebook looking very much the same as the palette window.
Is this working for Windows OS ?

 WindowFloating -> True, WindowFrame -> "Palette", 
 WindowElements -> {}, WindowTitle -> "x value", WindowSize -> All, 
 Editable -> False, Selectable -> False, ShowCellBracket -> False, 
 WindowFrameElements -> {"CloseBox"}]

(Most of the options used here are presented in these docs).

It looks like this for me (OSX, v10.0.2)

enter image description here

2. Docked Cell

Instead of creating a separate window, it is possible to display some content at the top of the notebook with DockedCells. This should provide here also a useful solution for the OP, as (for some reasons) the problem is to avoid "to scroll down and up to find that variable and change its value".

Define any content you need, for example here :

mydock = Row[{"x = ", InputField[Dynamic@x, FieldSize -> Tiny]}];

and dock it this way :

 DockedCells -> Cell[BoxData[ToBoxes[mydock]], "DockedCell"]]

enter image description here

To undock :

SetOptions[InputNotebook[], DockedCells -> {}]
  • $\begingroup$ I would be grateful if you could also explain, how it works. Indeed, evaluation creates a dialog with the input field in which x stays. What to do next? $\endgroup$ Feb 10, 2015 at 8:48
  • $\begingroup$ @AlexeiBoulbitch Instead of writing in the notebook x=somevalue, the dialog lets you directly enter somevalue(then you have to validate that with the Enter key in order x is set to that value). You can also write InputField[Dynamic@x]in the notebook, this works the same. For some reasons, the OP wanted it to be in a separate window, this is the purpose of CreatePalette. $\endgroup$
    – SquareOne
    Feb 10, 2015 at 11:00
  • $\begingroup$ @AlexeiBoulbitch Note that if xis modified in the notebook, the value in the dialog (inputfield) is automatically changed to that value also. That means that this separate window might also be useful to easily track the values of some variables during some computation ... $\endgroup$
    – SquareOne
    Feb 10, 2015 at 11:07
  • $\begingroup$ This is what I would expect, and this is what, indeed, happens, if I use the InputField[Dynamic@x] . However, when I tried to do the same with CreatePalletestuff, it astonishingly did not work, and I could neither modify x from the palette, nor evaluate the notebook cell containing x. This is the reason for my question. I have Mma10.0.2 at Win7. $\endgroup$ Feb 10, 2015 at 13:28
  • $\begingroup$ @AlexeiBoulbitch Do you confirm that you also set the option WindowClickSelectto True when creating the palette ? If yes, maybe it is a system specific problem ?? (I have v10.0.2 but with OSX) $\endgroup$
    – SquareOne
    Feb 10, 2015 at 18:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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