====== Using a local variable in a button command ======
This page is part of the Tcl/Tk page of the Airplug documentation.\\
[[en:doc:pub:tcltk:start|Back to the Tcl/Tk page]] /
[[en:doc:summary|Back to Airplug documentation page]].
---
The following code
button .bt -command { compute $var }
allows to call the compute procedure with the variable ''var'' when clicking on the button.
However, if this variable is local and is no more known when the user clicks on the button, there is an error. A solution consists in executing the delayed command in the correct namespace or to define the ''var'' variable in the global namespace.
However, if the above line of code is reused with a new value of ''var'', the same computation will be done even if several buttons are defined for different values of ''$var''. A solution consists in replacing ''$var'' by its value before the after call:
set cmd "compute $var"
eval { button .bt -command $cmd }
----
This page is part of the Tcl/Tk page of the Airplug documentation.\\
[[en:doc:pub:tcltk:start|Back to the Tcl/Tk page]] /
[[en:doc:summary|Back to Airplug documentation page]].