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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with dynamic binding in BLT-tabset 2

Status
Not open for further replies.

batewoman

Programmer
Aug 4, 2003
5
DE
hello,
i need to build a tabset with 24 folders (for each letter one), and they are all supposed to show the same text widget with different content. for the moment however, i don't even manage to display the text widget properly.
The code would be this:

tabset .ts
pack .ts

set x {a b c d} # an abbrev. list, one letter for a tab
set i 0
text .ts.text # the text widget to be shown

foreach element $x {
.ts insert $i $element -text $element
.ts tab configure "$element" -command {.ts tab configure $element -window .ts.text}
incr i
}


If anything, this code only shows the text widget on the last side of the tabset. Can anybody help me?
Thanks, Beate
 
Hi, I've finally located the fault in the script myself. Just in case anybody's interested: the command in the foreach-loop that binds the text widget to each folder should run correctly:

ts tab configure "$element" -command [eval "list .ts tab configure $element -window .ts.text"]

Beate
 
Actually, the simpler and safer way to do this is:

Code:
.ts tab configure "$element" -command     [list .ts tab configure $element -window .ts.text]

For all practical purposes, you can think of a Tcl command as being a Tcl list in which the first element is the name of the command to execute, and each remaining element is passed as an argument to the command. So, we can use list manipulation commands safely to build a well-structured list that we then use as a well-structured command.

The reason we use the list command in this instance is that we need to force immediate variable substitution in the command we're registering as the callback, rather than allowing the variable substitution to occur when the callback is executed. In your example, because the values of the element won't have spaces or other "list-significant" characters in it, you could also get by with:

Code:
.ts tab configure "$element" -command     ".ts tab configure $element -window .ts.text"

But this would fail if element were to contain spaces, tabs, quotes, brackets, etc. By using the list command, as shown above, any such characters are properly handled to ensure the value is treated as a single, literal list element -- which in turn will be a single, literal command argument.

- Ken Jones, President, ken@avia-training.com
Avia Training and Consulting, 866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top