#!./wish

proc AddIndicators {t l} {
    set r0 ""
    set r1 ""
    for {set i 0} {$i<200} {incr i} {
        set r0 "$r0[expr $i/10]"
        set r1 "$r1[expr $i%10]"
    }
    
    $l insert end "$r0"
    $l insert end "$r1"
    $t insert end "$r0\n"
    $t insert end "$r1\n"
    for {set i 3} {$i < 50} {incr i} {
        $l insert end "$i"
        $t insert end "$i\n"
    }
}

proc MakeSwitcher {w t l} {
    global gridowner

    frame $w
    label $w.label -text "Gridowner: "
    radiobutton $w.t -text "Text" -variable gridowner -value text \
        -command "$l configure -setgrid 0; $t configure -setgrid 1"
    radiobutton $w.l -text "Listbox" -variable gridowner -value listbox \
        -command "$t configure -setgrid 0;$l configure -setgrid 1"
    
    if {1 == [$t cget -setgrid]} {
        set gridowner text
    } else {
        set gridowner listbox
    }
    pack $w.label $w.t $w.l -side left
}

proc Resize {y} {
    global l t
    place $l -relheight $y
    place $t -relheight [expr {1.0 - $y}]
}

wm geom . +0+0

set l .p.l
set t .p.t

frame .p -height 400 -width 300
listbox $l -height 10
text $t -wrap none -setgrid 1

MakeSwitcher .s $t $l
AddIndicators $t $l

place $l -relwidth 1
place $t -relwidth 1 -rely 1 -anchor sw

pack .s -side top
pack .p -fill both -expand 1
Resize .40
