Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Create a button that is automatically disabled when clicked and enabled when it finishes running its code
ResourceFunction["DynamicEnabledButton"][label,action] represents a button that is labeled with label, evaluates action whenever it is clicked and automatically becomes disabled while action is evaluating. | |
ResourceFunction["DynamicEnabledButton"][Dynamic[x],label,action] binds the enabled state to x. |
Alignment | Automatic | how to align contents within the button |
Appearance | Automatic | the overall appearance of the button |
AutoAction | False | whether to click the button automatically when the mouse is over it |
Background | Automatic | button background color |
BaselinePosition | Automatic | alignment relative to surrounding text |
BaseStyle | "GenericButton" | base style specifications for the button |
ContentPadding | True | whether to shrink the margins tightly around the contents |
Enabled | Automatic | whether the button is enabled or grayed out |
Evaluator | Automatic | the kernel in which to evaluate expr |
FrameMargins | Automatic | minimum margins to leave inside the frame |
ImageMargins | 0 | margins around the image of the displayed button |
ImageSize | Full | the overall image size of the displayed button |
Method | "Queued" | the evaluation method to use |
Tooltip | None | the tooltip for the button |
TooltipDelay | 0.` | how long to delay before displaying the tooltip |
TooltipStyle | {} | style specifications for the tooltip |
Create a button that automatically becomes disabled while it is running code:
In[1]:= |
Out[1]= |
Provide a symbol that is updated automatically as the button changes state:
In[2]:= |
Out[2]= |
Use a dynamic label:
In[3]:= |
Out[3]= |
Embed in other expressions:
In[4]:= |
Out[4]= |
Control the state of the button by setting values for the given symbol:
In[5]:= |
Out[5]= |
In[6]:= |
Out[6]= |
Use another control:
In[7]:= |
Out[7]= |
Change the label depending on the state of the button:
In[8]:= |
Out[8]= |
Create a group of buttons where only one can be clicked at a time:
In[9]:= |
Out[9]= |
Create multiple button groups:
In[10]:= |
Out[10]= |
Use in a graphics expression:
In[11]:= |
Out[11]= |
Display the label literally, without the appearance of a button:
In[12]:= |
Out[12]= |
The state need not be bound to a symbol:
In[13]:= |
Out[6]= |
Use the TaggingRules of the current notebook to store the button state:
In[14]:= |
Out[14]= |
Get the button state using CurrentValue:
In[15]:= |
Out[15]= |
Change the state:
In[16]:= |
Out[16]= |
To use a label of the form Dynamic[…] without specifying the dynamic binding, None can be used as the first argument to avoid ambiguity:
In[17]:= |
Out[17]= |
Different predefined alignment options:
In[18]:= |
Out[18]= |
Predefined button appearances:
In[19]:= |
Out[19]= |
On some platforms, the following appearances are also defined:
In[20]:= |
Out[20]= |
Use a second element to get the appearance of a pressed button:
In[21]:= |
Out[21]= |
Use a special appearance for the button:
In[22]:= |
Out[22]= |
By default, the button function does not evaluate until you click it:
In[23]:= |
Out[23]= |
By setting AutoAction, the button function evaluates as you mouse over the button area:
In[24]:= |
Out[24]= |
Change the background colors:
In[25]:= |
Out[25]= |
Change the background color on every click:
In[26]:= |
Out[26]= |
Align with the surrounding text:
In[27]:= |
Out[27]= |
Change the baseline position on every button click:
In[28]:= |
Out[28]= |
Remove extra whitespace around a label with no ascenders or descenders:
In[29]:= |
Out[29]= |
By default, DynamicEnabledButton is enabled:
In[30]:= |
Out[30]= |
By setting Enabled→False, the button is disabled but visible in its current state:
In[31]:= |
Out[31]= |
By starting the button with Enabled→False, the button can still be enabled manually by altering the given symbol:
In[32]:= |
Out[32]= |
In[33]:= |
Out[33]= |
Use preset values:
In[36]:= |
Out[36]= |
Or use any values:
In[37]:= |
Out[37]= |
By setting the second element, you can also control the height:
In[38]:= |
Out[38]= |
A fully customized image size:
In[39]:= |
Out[39]= |
Make a button that automatically indicates when it is busy computing something:
In[40]:= |
Out[40]= |
Create a button that deletes itself after spending a few seconds to express how it feels about being deleted:
In[41]:= |
Similar behavior to DynamicEnabledButton[Dynamic[x],label,action] can be achieved with Button:
In[42]:= |
Out[42]= |
In[43]:= |
Out[32]= |
The enabled state of the button is restored even if an abort occurs:
In[44]:= |
Out[44]= |
This prevents the button from ending up in a “bad” state:
In[45]:= |
Out[32]= |
The appearance of the button will not update when using Method→"Preemptive":
In[46]:= |
Out[46]= |
In DynamicEnabledButton[Dynamic[x],label,action], the symbol x must not be a DynamicModule symbol in order for the enabled state to update:
In[47]:= |
Out[47]= |
This is also true for Button:
In[48]:= |
Out[48]= |
The dynamic binding must have just one argument and no options:
In[49]:= |
Out[49]= |
If the binding is unable to be set, no errors will be triggered when the button is created:
In[50]:= |
Out[48]= |
In[51]:= |
Out[51]= |
Messages will appear when the button code executes and the state of the button will fail to update:
In[52]:= |
Out[52]= |
Watch Birdnardo do a flip:
In[53]:= |
Out[53]= |
This work is licensed under a Creative Commons Attribution 4.0 International License