Add a Python script to a widget in a dashboard to register and respond to events you specify.
-
In Dashboards, open the dashboard you want to add a Python
script to.
-
Click
.
-
Add a widget to the panel.
-
In the
configuration pane, under
Scripts, click
+ to add an event script to the widget.
The
Script window opens.
-
Select the type of event.
Type of Event
|
Description
|
Binding updated
|
Executes when the values for the widget's binding updates.
|
Loaded
|
Registers when the widget loads.
|
State changed
|
Registers when the widget transitions from one state to another state.
|
Timer
|
Executes the script at the time interval you specify.
|
User input
|
Executes when a user provides new values

Note
Only output widgets have the option to create a script for the user input event.
|
-
Enter a unique name for the main function, or the entry point that the script calls when the event executes.

Note
If you do not name the main function,
Dashboards automatically wraps the script in an anonymous Python function
and nests all of the functions inside of it.
-
In the Script window, enter
def and press Ctrl+Space to autogenerate the function definition and return statement.
-
Add your Python code.
You can call two Python functions from a script to access the dashboard widgets. Refer to the following table to learn more
about the Python functions.
Name of Function
|
Description
|
Function
|
Get Widget Properties
|
Returns the value of the requested widget property in the configuration pane.
|
get_widget_prop(widget_name, property_name)
|
Set Widget Properties
|
Writes the value of the requested widget property.
|
set_widget_prop(widget_name, property_name, value)
|
-
When you finish adding your Python code, click
OK.
Dashboards lists the script in the configuration pane.
-
Click
Save and
Play to view your dashboard.
-
To make changes to the event script, double-click the event script in the
configuration pane.

Note
You cannot change a script's event type. To do so, you must delete the existing event script and add it to a new event.
After you add an event script to a widget, add a virtual tag script to your dashboard to enable communication between your
event script and widget.