Tcl/Tk Cookbook - Basics of Tk


Part -II - Step 1: Create app1

Script

#!/usr/bin/wish
global b

frame .r -bd 2
wm title . "Change Me"
pack .r
button .r.b -text "Press Me to Quit"  -command {exit}


pack .r.b
set b [.r.b config]            ;# obtain default settings


proc reJig { va a} {

	.r.b config $a $va
	}

Much of this code is explained already in part-I. The parent frame is ".r" rather than ".rc". The window title is changed and the list of current configuration "b" has changed in scope and is declared as global.

Note that Tcl has a single global name space in which it retains all widget names. Therefore you do not have to declare widgets as global and can access a widget by giving its full name from within procedures.

reJig takes the values of the configuration option and the corresponding new value as its input and calls the widget command .r.b to carry out the "configure" action.

Create this script and execute it to see the result:

Note: If you executed this script and it is running, then don't quit it. You will require av to be active when you execute av2 and set the inter communication going.