HELP geometry settings

From: Bruce Hartweg (bruce-news_at_hartweg.us)
Date: 10/27/04


Date: Tue, 26 Oct 2004 18:05:11 -0500

Ok,
   I;ve made plenty of complicated GUIs in my time and normally
Tk does them with no muss no fuss, and even if it *was* tricky
I was able to make it work. But now I seem to be stuck :(
Especially frustrating is I seem to remember doing this before!
So now I turn to clt for help.

Here the situation, I have a GUI that is driven by external data
and so is fairly generic code, and dynamically driven.

I basically have N sections, in each section I want to display all
rows of data, and I want then entire GUI to have one vertical
scrollbar, BUT I want each section to scroll independantly inthe
horizontal direction. but I want them to grow as big as the window
if user stretches it

I have basically got this to almost work, except the width of
each section never gets wider. (run code below to see what I
am describing.

basically in both cases I am using the frame-in-a-canvas to
do the scrolling. in both cases a bind on Configure for a
frame updates the scrollregion on the holding canvas, for the
individual section it also forces the canvas to grow in height
to match it (works great). for the top level the scroll part
work fine, but I also add a bind for Configure to the canvas
to force the width of the enclosed frame to be the same. This
should then stretch the individual section out because they
are packed with a -fill x (i also tried using grid - no change)
I've added various tracing to the configure bindings and
see that when the canvas gets a config it does a setting of the
width of a frame, the frame config fires with that width, and
then immediately andother config fires that changes the width
right back! please offer any help that works

Thanks,
   Bruce

CODE EXAMPLE:

package require Tk
proc buildGUI {} {

    canvas .c -yscrollcommand ".y set"
    scrollbar .y -command ".c yview"

    pack .y -side right -fill y
    pack .c -expand 1 -fill both

    frame .c.f
    .c create window 0 0 -anchor nw -window .c.f

    # if frame changes size, update scroll region of canvas
    bind .c.f <Configure> ".c configure -scrollregion {0 0 %w %h}"

    # if canvas changes size, force width of frame to match
    # but leave height alone
    bind .c <Configure> ".c.f configure -width %w"

    # now add stuff
    set cnt 0
    foreach {nrow ncol} { 2 7 4 8 3 13 2 2 } {
         set lf [labelframe .c.f.frm[incr cnt] -text "Section $cnt"]
           buildSection $lf $nrow $ncol
        pack $lf -fill x
    }
}

proc buildSection {p nr nc} {
    set a [frame $p.a]
    set s [canvas $p.c -xscrollcommand "$p.x set"]
    set x [scrollbar $p.x -command "$s xview" -orient horizontal]
    set f [frame $s.f]

    grid $a $s -sticky news
    grid x $x -sticky news
    grid rowconfigure $p 0 -weight 10
    grid columnconfig $p 1 -weight 10

    $s create window 0 0 -anchor nw -window $f

    grid [label $a.l -text " "] -row 0
    for {set c 1} {$c <= $nc} {incr c} {
       grid [label $f.h$c -text "HEADER-$c"] -row 0 -column $c
    }

    for {set r 1} {$r <= $nr} {incr r} {
       grid [label $a.l$r -text " Row $r"] -row $r
       for {set c 1} {$c <= $nc} {incr c} {
          grid [label $f.h$r-$c -text "Data $r,$c"] -row $r -column $c
       }
    }

    # if frame changes size force canvas to same height
    # and adjust scollregion
    bind $f <Configure> "$s configure -height %h -scrollregion {0 0 %w %h}"

    # if canvas changes size scroll region adjusts on its own
}
catch {console show}
buildGUI



Relevant Pages

  • Scrolling canvas with embedded windows
    ... I know, in general, how to make a scrolling canvas. ... noticed a difference in how they scroll. ... Some ways refresh the widgets as they scroll, ... # "B" labels are children of frame, ...
    (comp.lang.tcl)
  • Re: Scrolling canvas with embedded windows
    ... > noticed a difference in how they scroll. ... > Some ways refresh the widgets as they scroll, ... > # Put something visible on the canvas so we have a sense ... > # Frame is embedded in canvas, ...
    (comp.lang.tcl)
  • Resize question
    ... I'm building a small app that would benefit from a scrolled frame. ... found a resonable example in Brent Welch's book using a canvas widget. ... .# Using a canvas to scroll a set of widgets. ...
    (comp.lang.tcl)
  • Re: Scrollable canvas with images
    ... > scroll a frame, what is the purpose of a canvas? ... The purpose of the canvas is to be a versatile widget to draw ...
    (comp.lang.tcl)
  • 2 Table and 1 vertical scroll
    ... Hi few days back I had a query relating "2 Table and 1 vertical scroll, ... In GUI, table1 is big and table 2 is small. ... #this frame will contain x and y scroll and a table ... ".ss.time.right.cright xview" ...
    (comp.lang.tcl)