Re: about the canvas widget



Hi, Bryan Oakley
Thank you. as the frame doesn't need pack or grid manually, it is
packed by the canvas create command. so "propagate" command will not
work.
now, I have done it by following method, the canvas should be
packed firstly..
//////////////////////////
set width [winfo width $can]
set height [winfo height $can]
set mf [frame $can.mf -bg red ]
$can create window 0 0 -anchor nw -window $mf -width $width -tag
FILL
/////////////////////////////////////////

and the proc resize_frame redeveloped as follows, so the frame can
daynamically expand and fill the space of the canvas.
proc resize_frame {canvas frame} {
puts "enter resize frame proc."
set width [winfo width $canvas]
#set height [winfo height $canvas]
$canvas itemconfigure FILL -width $width

}

Best Regards.
Tony

"
(we normally bottom-post in this newsgroup, but I'm sticking to the
style of the original poster...)

Most likely you have one or more widgets inside that inner frame, and
you have it configured (via the tk defaults) to have the size of the
frame controlled by its contents. Most of the time this is what one
wants; your case is one of the times you want something else to control
the size of the frame.

You need to do either "pack propagate $mf 0" or "grid propagate $mf 0"
(depending on how you add widgets to $mf) and see if that fixes the
problem. If it works, be sure to take the time to read the man page
description of the "propogate" subcommand so you understand why this works.


sunnyboyGuo@xxxxxxxxx wrote:
Hi, Bryan Oakley,
I have modified my code according your method, but it didn't work as my
expectation.
when I resize the window, the canvas will resize automatically and fire
the proc resize_frame. and the output width and height of the frame had
the same value as the output of canvas dynamically. but the display of
the frame didn't change anything. what's
wrong?
Suppose the frame has one child widget, a button, so the frame just
require the corresponding space to display the button. while the
require width and height of the frame is less than the available space
of the canvas. It didn't adjust its display according the configuration
above.

Best Regards.
Tony

proc resize_frame {canvas frame} {
puts "enter resize frame proc."
set width [winfo width $canvas]
set height [winfo height $canvas]
$frame configure -width $width -height $height
puts "canvas: $width, $height"
puts "frame: [winfo width $frame], [winfo height $frame]"
puts "frame: [winfo reqwidth $frame], [winfo reqheight $frame]"

}


"Bryan Oakley 写道:
"
guojiaoyang@xxxxxxxxx wrote:
Hi all,
my tcl code as follows, the canvas widegt will expand and fill the
frame "fmid" which also expand and fill his parent widget "." now, I
want the frame "mf" in the canvas widget can expand and fill the canvas
widget. Can I do this? Could you help me?
////////////////////////////////////////////////////tcl code
wm geometry . 600x420
wm resizable . 0 0
set fmid [frame .fmid]
pack $fmid -expand true -fill both
scrollbar $fmid.vscroll -command "$fmid.canvas yview"
pack $fmid.vscroll -side right -fill y
canvas $fmid.canvas -relief flat -borderwidth 0 -width 410 \
-yscrollcommand "$fmid.vscroll set"]
pack $fmid.canvas -side right -expand true -fill both

set mf [frame $fmid.canvas.mf ]
$fmid.canvas create window 0 0 -anchor nw -window $mf
#
# create and pack widget in the frame "mf".
#
///////////////////////////////////////////////////

Best Regards.
Tony

It will be necessary to have the frame sized to fit the canvas. This can
be done automatically with something like this:

bind $fmid.canvas <Configure> \
[list resize_frame $fmid.canvas $fmid.canvas.mf]

proc resize_frame {canvas frame} {
set width [winfo width $canvas]
set height [winfo height $canvas]
$frame configure -width $width -height $height
}

The <Configure> event fires whenever the canvas is resized. Thus,
whenever the canvas changes size we force a resize of the frame.

You may need to modify the code to account for borderwidths and such,
but that's just a matter of doing some simple math on $width and $height
before using it to configure the frame.


.



Relevant Pages

  • Re: Is this now a "redraw/resize plotchart" question?
    ... delete+recreate the canvas too, but there may have been other ... proc doContents {xpixels ypixels first} { ... set ypixels [winfo height .c] ...
    (comp.lang.tcl)
  • Re: "Holiday season"
    ... to trace his sweet baby scrawl onto a piece of dry canvas (any plain ... then i used ordinary black thread to stitch the ... letters onto the canvas, including his signature, a jumbly "ALeX" with the ... frame i had lying around the attic (but frames can be had for practically ...
    (alt.support.arthritis)
  • Re: "Holiday season"
    ... i used one of my son's letters to santa; the first one he wrote, ... to trace his sweet baby scrawl onto a piece of dry canvas (any plain fabric ... then i used ordinary black thread to stitch the ... frame i had lying around the attic (but frames can be had for practically ...
    (alt.support.arthritis)
  • Re: about the canvas widget
    ... frame controlled by its contents. ... when I resize the window, the canvas will resize automatically and fire ... the same value as the output of canvas dynamically. ... Suppose the frame has one child widget, a button, so the frame just ...
    (comp.lang.tcl)
  • Re: canvas with large window (frame)
    ... Bruce Hartweg wrote: ... >> I add the frame to a canvas as a single window to enable ...
    (comp.lang.tcl)