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
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 $ -bg red ]
$can create window 0 0 -anchor nw -window $mf -width $width -tag

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.

(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
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
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

Best Regards.

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 create window 0 0 -anchor nw -window $mf
# create and pack widget in the frame "mf".

Best Regards.

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 $]

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.