HELP geometry settings
From: Bruce Hartweg (bruce-news_at_hartweg.us)
Date: 10/27/04
- Next message: Steve Ball: "Re: tcl DOM - can the standard tags be removed?"
- Previous message: Pat Thoyts: "Re: How to spy on a USB port on Win2k?"
- Next in thread: Peter Spjuth: "Re: HELP geometry settings"
- Reply: Peter Spjuth: "Re: HELP geometry settings"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: Steve Ball: "Re: tcl DOM - can the standard tags be removed?"
- Previous message: Pat Thoyts: "Re: How to spy on a USB port on Win2k?"
- Next in thread: Peter Spjuth: "Re: HELP geometry settings"
- Reply: Peter Spjuth: "Re: HELP geometry settings"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|