Wolfram Language Fast Introduction for Programmers
Get Started »

Interactive Interfaces

You can take any expression and manipulate it with controls that change values of variables:

In[1]:=
X
Out[1]=

The Manipulate command greatly simplifies GUI creation, automatically inferring control types and layout based on parameter specifications. Interface creation in Java requires the use of Swing, AWT or a third-party GUI library, typically with many more lines of code.

There is no direct analogue for the Wolfram Language function Manipulate in Python. To create an interface, Python requires building a GUI using Tkinter or another third-party GUI library, typically with many more lines of code.

Notice that the Wolfram Language can infer what GUI controls to generate based on its input.

Manipulate uses the standard min, max, step iterator specification:

In[2]:=
X
Out[2]=

In the Wolfram Language, controls are just symbolic expressions:

In[1]:=
X
Out[1]=

Make a button by giving an expression to evaluate when the button is pressed:

In[2]:=
X
Out[2]=

QUICK REFERENCE: Interactive Controls »

Dynamic displays as the dynamically updated value of an expression.
(This is always possible in local, desktop versions; support may be limited in the cloud.)

Move the slider to get the value of x to change:

In[1]:=
X
Out[1]=

Show the current value:

In[2]:=
X
Out[2]=

Always display the current value:

In[3]:=
X
Out[3]=

Dynamic is a powerful construct for tying values together and has no direct analog in Java. Java would require a method call, background threads or additional logic to update the display every time x changes.

Dynamic is a powerful construct for tying values together and has no direct analogue in Python. Python would instead require manually updating the display every time x changes.

QUICK REFERENCE: Interactive Interfaces »

Check Your Understanding

Which of the following makes a Manipulate with a slider for x from 1 to 4?

Manipulate[ListLinePlot[{1, 3, x, 4, 1, 3, x}], {x, 1, 4}]

Correct.

Dynamic[ListLinePlot[{1, 3, x, 4, 1, 3, x}], {x, 1, 4}]

Incorrect. The right function to use here is Manipulate.

Slider[ListLinePlot[{1, 3, x, 4, 1, 3, x}], {x, 1, 4}]

Incorrect. The right function to use here is Manipulate.

If one puts x = 2 in a first cell and Dynamic[x] in a second cell, then sets x = 4 in a third cell, what is in the output of the second cell after those three cells are evaluated?

2

Incorrect. When the second cell is evaluated, it returns the value of x as 2, but when the third cell is evaluated, the value of x changes to 4. Because Dynamic[x] always uses the current value, it will give an output of 4.

x

Incorrect. The value of x has been set, so it no longer returns as a symbol.

4

Correct.

Which of these gives a button that sets the value of x to 4?

Manipulate["set x to be 4", {x, 4, 10}]

Incorrect. This is a Manipulate, not a button. Also, this variable x is local and won't change the global value of x.

TabView[{x, 4}]

Incorrect. This is a tab, not a button.

Button[x = 4, "set x to 4"]

Incorrect. The arguments go the other way around.

Button["set x to be 4", x = 4]

Correct.