Re: Scrolling canvas with embedded windows
From: Gerald Lester (Gerald.Lester_at_cox.net)
Date: 11/22/03
- Next message: Donald Arseneau: "Re: TIP #166: Reading and Writing the Photo Image Alpha Channel"
- Previous message: marvin: "Re: tcl/tk visual gipsy --beginner questions"
- In reply to: John Seal: "Scrolling canvas with embedded windows"
- Next in thread: John Seal: "Re: Scrolling canvas with embedded windows"
- Reply: John Seal: "Re: Scrolling canvas with embedded windows"
- Reply: John Seal: "Re: Scrolling canvas with embedded windows"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 21 Nov 2003 19:41:00 -0600
John Seal wrote:
> I know, in general, how to make a scrolling canvas. But I want to
> scroll a complex arrangement of widgets, and I want to use a nice
> friendly geometry manager to arrange them. I've tried several ways, and
> noticed a difference in how they scroll. This behavior is observed on
> both Mac OS X Jaguar 10.2.8 running Wish Shell 8.4.4, and also Mac OS
> 9.2.2 running Tclkit 8.4.0.
>
> Some ways refresh the widgets as they scroll, and some don't. Take a
> look at this sample code, taken from the Wiki "Minimal Scrolling Canvas"
> in the grid version, with four arrangements of widgets added:
>
> # Original Wiki code begins here.
>
> set height 400
> set width 600
> set borderwidth 2
>
> set hscroll .hscroll
> set vscroll .vscroll
> set canvas .c
>
> scrollbar $hscroll -orient horiz -command "$canvas xview"
> scrollbar $vscroll -command "$canvas yview"
> canvas $canvas -relief sunken -borderwidth $borderwidth \
> -width $width -height $height \
> -xscrollcommand "$hscroll set" \
> -yscrollcommand "$vscroll set"
> # Ensure that window resizings retain scroll bars.
> grid $canvas -row 0 -column 0 -sticky nswe
> grid $vscroll -row 0 -column 1 -sticky ns
> grid $hscroll -row 1 -column 0 -sticky ew
> grid rowconfig . 0 -weight 1
> grid columnconfig . 0 -weight 1
> # Put something visible on the canvas so we have a sense
> # of what we're seeing.
> $canvas create line 0 0 $width $height
> $canvas create line 0 $height $width 0
> $canvas configure -scrollregion [$canvas bbox all]
>
> # Original Wiki code ends here, and my additions begin.
>
> # "A" labels are children of canvas, gridded in canvas.
> foreach label {a1 a2 a3 a4 a5} {
> set w $canvas.a$label
> label $w -text $label
> grid $w
> }
No, no, no no no no no!
Don't every every grid things into a canvas!
You only every every grid/pack/place things into frames or toplevels.
Use the canvas "create window" command/method -- please read the canvas man page!
> # "B" labels are children of frame, gridded in frame.
> # Frame is embedded in canvas, but otherwise unmanaged.
> set frame .f1
> frame $frame
> foreach label {b1 b2 b3 b4 b5} {
> set w $frame.b$label
> label $w -text $label
> grid $w
> }
> $canvas create window 0 0 -anchor nw -window $frame
I see you've read the page.
> # "C" labels are children of canvas, embedded in canvas,
> # but otherwise unmanaged.
> set y 10
> foreach label {c1 c2 c3 c4 c5} {
> set w $canvas.c$label
> label $w -text $label
> $canvas create window 40 $y -anchor nw -window $w
> incr y 30
> }
This is the way to use the canvas.
> # "D" labels are children of toplevel, gridded in frame.
> # Frame is embedded in canvas, but otherwise unmanaged.
> set frame .f2
> frame $frame
> foreach label {d1 d2 d3 d4 d5} {
> set w .d$label
> label $w -text $label
> $canvas create window 0 0 -anchor se -window $w
> grid $w -in $frame
> }
> $canvas create window 80 0 -anchor nw -window $frame
>
> # End of sample code.
>
> The A widgets are unsatisfactory because they get gridded in the canvas
> widget window and don't scroll with the canvas. The B widgets scroll,
> but they don't refresh until you release the scroll thumb. The C
> widgets scroll "live", but I have to compute their positions instead of
> letting a geometry manager do that for me. The D widgets scroll "live"
> and let me use a geometry manager, but it sure seems like an unusual way
> to do it.
>
> Is there a better way to get "live" scrolling of widgets complexly
> arranged using a geometry manager?
The canvas is a drawing tool. You want a scrolledframe, please see:
http://wiki.tcl.tk/scrolledframe for pointers to the most common ones.
BTW, did you get the hint from my first comment that you should not be using
pack/place/grid to put windows in anything except toplevels and frames (out of
the base widget set).
-- +--------------------------------+---------------------------------------+ | Gerald W. Lester | "The man who fights for his ideals is | | Gerald.Lester@cox.net | the man who is alive." -- Cervantes | +--------------------------------+---------------------------------------+
- Next message: Donald Arseneau: "Re: TIP #166: Reading and Writing the Photo Image Alpha Channel"
- Previous message: marvin: "Re: tcl/tk visual gipsy --beginner questions"
- In reply to: John Seal: "Scrolling canvas with embedded windows"
- Next in thread: John Seal: "Re: Scrolling canvas with embedded windows"
- Reply: John Seal: "Re: Scrolling canvas with embedded windows"
- Reply: John Seal: "Re: Scrolling canvas with embedded windows"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|