Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Binding a collection of controls to a same procedure

Status
Not open for further replies.

pluto1974

Programmer
Mar 1, 2005
3
US
I have a collection of button controls
Instead of binding in this way,

bind .Btn1 <ButtonPress> {display}
bind .Btn2 <ButtonPress> {display}
bind .Btn3 <ButtonPress> {display}

All the bindings should map to the same procedure.

I tried in this way.
for { set x 1} { $x <= $counter} {incr x} {
bind .Btn$x <ButtonPress> { display } }

There is no error.
But it is not responding...

Any ideas would be helpful.

Thanks
 
The button widget is already bound with the "-command" option. Why not just specify -command <yourProc> for all the buttons when you define them?

Bob Rashkin
rrashkin@csc.com
 

Thanks for you reply Bong.

But the SDK that i use for programming a POS device supports full TCL and a minor TK support.They have overrided most of the widgets options and we have a separate widget library and an engine to interpret that.
so I cannot use the -command option in that.

I tried using the "%W" argument of the bind command to get the path name of the widget...even it is not working...

Is this the correct way of using the script arguments in bind command?

bind .radioBtn$x <ButtonPress> {disp %W $counter listNames}


Thanks.
 
The syntax looks ok but I think the <ButtonPress> event (at least the way I use it) is <Button-1> for the left click (<Button-3> for the right click).

Bob Rashkin
rrashkin@csc.com
 
This device has a touchscreen and there are no mouse events.
and the click event is just <ButtonPress> for the widgets in this SDK.
Anyhow Thanks Bong.
I found another way by using a temporary list and sending the buttons names by substitution as like below:

for { set x 1} { $x <= $counter} {incr x} {
set ctrlName [lindex $radioCtrlNameList [expr $x - 1]]
bind $radioCtrlName$x <ButtonRelease> "disp $ctrlName $counter {$listNames}"
bind "$radioCtrlName{Sub}$x" <ButtonRelease> "disp $ctrlName $counter {$listNames}" }


and creating that radioCtrlNameList list while creating the buttons.

Thanks once again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top