"Timer"
Widget["Timer"]
creates a timed action.
Details
Examples
Basic Examples
Interactive Examples
See Also
Tech Notes
GUIKit`
GUIKit`
"Timer"
The functionality provided by GUIKit has been superseded by the interface construction and controls functions native to the built-in Wolfram Language.
Widget["Timer"]
creates a timed action.
Details
- To use Widget["Timer"], you first need to load GUIKit using Needs["GUIKit`"].
- Widget["Timer"] is a useful nonuser interface widget that creates a timed action to which you can bind calls. It can be started and stopped, and its "delay" property in units of milliseconds can be changed while it is running.
- The following properties are available:
-
"delay" the time in milliseconds between events "initialDelay" the initial delay in millliseconds before the first event fires - The following event is available:
-
"action" the event triggered each time the timer is set - The following methods are available:
-
"start" requests that the timer begin firing actions "stop" requests that the timer stop firing actions
Examples
open all close allBasic Examples (1)
Needs["GUIKit`"]ref = GUIRun[
Widget["Frame", {
"title" -> "Timer Example",
{Widget["Button", {"text" -> "Start",
BindEvent["action",
InvokeMethod[{"myTimer", "start"}]]}],
Widget["Button", {"text" -> "Stop",
BindEvent["action",
InvokeMethod[{"myTimer", "stop"}]]}]},
Widget["Slider", {"minimum" -> 50, "maximum" -> 3000,
"value" -> 1000,
BindEvent["change",
Script[ SetPropertyValue[{"myTimer", "delay"},
PropertyValue[{"slider", "value"}] ]]]},
Name -> "slider"],
Widget["Timer", {"delay" -> 1000,
BindEvent["action",
Script[Print["timer triggered!"]]]},
Name -> "myTimer"]
}]
]GUIScreenShot[ref]Interactive Examples (1)
Needs["GUIKit`"]Fire a stream of events only when a button is held down for a length of time:
ref = GUIRun[
Widget["Panel", {
Widget["Button", {"text" -> "Print",
BindEvent["mousePressed", InvokeMethod[{"myTimer", "start"}]],
BindEvent["mouseReleased", InvokeMethod[{"myTimer", "stop"}]]
}],
Widget["Timer", {
"delay" -> 20,
"initialDelay" -> 0,
BindEvent["action",
Script[Print["timer triggered!"]]]},
Name -> "myTimer"]
}]
]