Append the following lines to appl1.tcl [ For clarity and good programming practice, place any global declarations at the top of the body the script (just below the line #!/usr/bin/wish) and in procedures immediately after the declaration of the procedure. Any initialisation should also be placed before the value is set or rest from within the script. ]
global aList vList
set aList {}
set vList {}
set maxl 0
set b [.rc.b config]
foreach e $b {
lappend aList [lindex $e 0]
lappend vList [lindex $e 4]
set a [lindex $e 0]
if { [string length $a] > $maxl } {
set maxl [string length $a]
}
}
The first line sets two global variables aList and vList and the next two lines initialise these two variables to null list. the last line sets a variable maxl to zero.
The command set b [.rc.b config] invokes the widget command .rc.b to get its list current configuration options and assigns it to the variable b. Note that b is a list of lists. Each nested list contains the configuration option such as -background followed by information regarding that option, the fifth of which is the value.
The first of the foreach loop access nested list "e" of the list "b"
Now you need to create an interface to display these pairs of values. The script below achieves this:
set i 0
frame .rc.fff -height 40
pack .rc.fff
foreach a $aList {
set ff [frame .rc.fff.sub$i]
pack $ff
label $ff.lab -text $a -width $maxl -anchor e
entry $ff.ent
bind $ff.ent [list reJig .rc.b $a]
$ff.ent insert 0 [lindex $vList $i]
pack $ff.lab $ff.ent -side left -in $ff
incr i
}
Set a counter "i", initialising it to zero. frame .rc.fff -height 40 creates a frame .rc.fff, of height 40 pixels as a child of .rc and pack .rc.fff packs it below the button .rc.b by default.
The foreach element "a" of the list "aList"
Note: As in any shell programming language, in Tcl/Tk too there are more than one way of achieving certain results. For instance the script for the binding could have been specified as "reJig .rc.b $a". Using [list * * ] ensures proper variable substitutions are carried out and a proper list structure whose elements together form a single command is generated.
If you try {reJig .rc.b $a}, you will find that "a" is not replaced by its value because it is within the curly braces. As a result the procedure reJig will receive the string $a rather than the value of a.
Note also that since the widget hierarchy name uniquely identifies a widget .rc.fff.sub0.ent is different from .rc.fff.sub1.ent.
Appending these lines of script in appl1.tcl and executing should produce: