waiting for input of widget and return input value



Hi, maybe that's a very easy question but i'm really confused by it and
cannot find an answer.
I wrote below tcl/tk script and hope to implement function like this:
run proc1, then proc1 will invoke proc2 and popup some checkbutton for
variables, then customer check some checkbutton, then click "Confirm"
to invoke proc3, proc3 will check which button was checked and return a
checked variable list, then proc2 return the list to proc1, and proc1
print it out.

proc proc1 {} {
set dev_list [proc2]
puts $dev_list
}

proc proc2 {} {
set w .add_new_env
catch {destroy $w_dev}
toplevel $w
set array1(1,1) "variable1"
set array1(2,1) "variable2"
set array1(3,1) "variable3"
for {set i 1} {$i<3} {incr i +1} {
checkbutton $w.$i -text $array1($i,1) -variable array1($i,2)
-anchor w
}
frame $w.command
button $w.command.confirm -text Confirm -command "catch {destroy
$w}; return [proc3 [array get array1]] "
button $w.command.cancel -text Cancel -command " catch {destroy $w}
; return 0 "
pack $w.command -side bottom -fill x -pady 2m
pack $w.command.confirm $w.command.cancel -side left -expand 1
}
proc proc3 {array_name} {
array set array1 $array_name
set list_value ""
for {set i 1} {$i <= 3} {incr i +1} {
if {$array1($i,2)==1} {
append list_value $array1($i,1)
append list_value ";"
}
}
return $list_value
}

The problems I encountered are:
1. proc1 will invoke proc2 , but proc2 won't wait for customer input
and return immediately. I know I can use vwait to solve this problem,
but vwait will stop total program( I have some other code in the same
main program is running). i don't like it. Is there any other way to
solve it?
2. proc3 will run immediately and does not wait for customer to click
"Confirm" button.
3. in the -command sentence, how can i get the return value from proc3
and then return it to proc1

Thanks for any help.

Hans Yin

.