Tcl/Tk Cookbook - Basics of Tk


Part-II - Step 3:Procedure to display attribute - value pairs of the appl 1 widget in appl 2

Script

Append to av2:



proc setCfg { b } { 

global aList vList

set maxl 0

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]
		}
	}


set i 0

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 ValCh $a] 
	$ff.ent insert 0 [lindex $vList $i]
	pack $ff.lab $ff.ent -side left -in $ff
	incr i
	}

button .rc.fff.b -text "Close" -com {exit}
pack .rc.fff.b 

}

Much of this code is familiar from Part-I. The procedure setCfg takes a list which is the result of carrying out the action "configure" by a widget command (.r.b in this case). Since this is an application in its own right, a button .rc.fff.b with the text "Close" and the command option with value "exit" is included.

New or changed lines of script are highlighted.