$Dlightsub::local.$1.[expr ([string map {0 {10}} $2] - 1)] is the name of the scale is want to set to 100 when i press the associated button and go back to 0 on release
First of all, I think it's [red]very bad[/red] to use numbers as variable names. So, sidestepping that, I go back to an earlier thread where we laid out some simple scales. For each of those I'll put in a button that, when pressed, sets the value of the corresponding scale variable to 100: #a frame for the controls
pack [frame .1 -borderwidth 4] -side top
#add the controls
pack [spinbox .1.s -textvariable circ -from 0 -to 512] -side left
pack [button .1.b -text go -command {MakeScales $circ}] -side left -padx 8
proc MakeScales {circ} {
#a frame for the scales
destroy .2
pack [frame .2 -borderwidth 4] -side top
set numRows [expr {$circ/10}]
set rmndr [expr {$circ%10}]
pack [frame .2.r] -side bottom
for {set i 0} {$i<$rmndr} {incr i} {
scale .2.r.s$i -variable subR$i
pack .2.r.s$i -side left
}
for {set r 0} {$r<$numRows} {incr r} {
pack [frame .2.$r] -side bottom
for {set i 0} {$i<10} {incr i} {
pack [scale .2.$r.$i -variable sub$r$i] -side left
}
}
[red]pack [frame .2.rr] -side top
for {set i 0} {$i<$rmndr} {incr i} {
pack [button .2.rr.$i -text subR$i -command "set subR$i 100"] -side left
}
for {set r 0} {$r<$numRows} {incr r} {
pack [frame .2.b$r] -side top
for {set i 0} {$i<10} {incr i} {
pack [button .2.b$r.$i -text "sub$r$i" -command "set sub$r$i 100"] -side left
}[/red]
}
}
Notice that you don't use ButtonPress for a button widget; that event is generated by a mouse button. You also don't need to bind the event to the button; it's already bound in the widget. The key here, though, is using "" rather than {}. Otherwise, the values of r and i will be substituted when the button is pressed instead of when it's instantiated.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.