This is documentation for Mathematica 6, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)


BindEvent[name|{target, name}|{target, name, filter}, object|script|call, ...]
binds an event from one object to a listener or to a script.
  • To use BindEvent, you first need to load GUIKit using Needs["GUIKit`"].
  • BindEvent causes script code or other method calls to be executed when an event is triggered from the targeted widget.
  • BindEvent returns the object instance listener that is created as a result of requesting the binding.
  • BindEvent is typically used with a Script block that gets evaluated in Mathematica when an action occurs.
  • If there is no target specified, the wrapping context Widget is the target.
  • With BindEvent[ name|{target, name}|{target, name, filter}, Script[...]], when the event name occurs, the script is processed.
  • With BindEvent[ name|{target, name}|{target, name, filter}, WidgetReference[listener]], the WidgetReference must resolve to an object that implements the appropriate listener interface.
  • If filter is specified, then only events that match that filter cause the script to be processed. In general, the filter is used to name a method in a listener type that has multiple methods (e.g., WindowEvent).
  • For event names "propertyChange" and "vetoableChange", the filter is the name of the property for which the binding should be done.
  • Each time a BindEvent action is triggered and the Script code is executed, specially registered objects associated with the current event are registered with the names "#", "#1", "#2" and so on, depending upon the number of arguments associated with the event listener callbacks. Almost all events register at least one object as "#" representing the event object associated with this action. Typically, you might request properties of the event object as in the case of mouse events that provide properties, such as "x" and "y", the location of the mouse.
  • In some rare cases it will be beneficial to trigger code execution that does not require evaluation in the kernel, specifically when a user interface would like to abort a currently executing evaluation through the user interface, typically with a Cancel button. This can be accomplished by associating an InvokeMethod request on a specially registered evaluator object referenced as "ScriptEvaluator", using BindEvent["action", InvokeMethod[{"ScriptEvaluator", "abort"}]]. The framework will always make sure such a reference is defined for any live user interfaces to allow the user to programmatically abort current Mathematica evaluations.
  • The following option can be given:
NameNonethe name with which to register the new listener in the object registry
  • Name -> "myName" registers the new listener in the object registry for future lookup using WidgetReference["myName"]. This naming and lookup could be useful if you want to dynamically add or remove the listener from the bound widget, essentially providing a way to remove the binding listener.
Bind a script to the "MouseMoved" event that prints the "x" and "y" property values of the mouse event: