Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

expand frame in canvas widget

220 views
Skip to first unread message

Ronny Frevert

unread,
Dec 2, 2002, 7:49:20 AM12/2/02
to
Hi all,

I took an example (see below) out of a Tcl/Tk book to create a
scrollable form using the canvas widget. Now the problem in my script
is, that the red frame "$win2.vport.form" covers only around 60 percent
of the blue canvas "$win2.vport" area. Now I'm looking for a command to
expand this frame inside this canvas widget. I changed also the anchor
in line xy to east, but the frame everytime occurs on the left. All
widgets inside this frame are expanded and only if I broad the widgets
inside, the frame "frame $win2.vport.form" will broaden too. Has anyone
an idea what could be wrong or which command could help?

Thank you,
Ronny


proc scrollform_create {win2} {

frame $win2 -class Scrollform

scrollbar $win2.sbar -command "$win2.vport yview"
pack $win2.sbar -side right -fill y

canvas $win2.vport -yscrollcommand "$win2.sbar set" -background blue
pack $win2.vport -side top -fill both -expand true

frame $win2.vport.form -background red
$win2.vport create window 0 0 -anchor nw -window $win2.vport.form
///// line xy

bind $win2.vport.form <Configure> "scrollform_resize $win2"
return $win2

}

Jeffrey Hobbs

unread,
Dec 3, 2002, 2:35:16 AM12/3/02
to
Ronny Frevert wrote:
> I took an example (see below) out of a Tcl/Tk book to create a
> scrollable form using the canvas widget. Now the problem in my script

My best recommendation would be to look into bwidgets or iwidgets, both
megawidgets packages that have such widgets included. Both of these are
also part of ActiveTcl:
http://www.activestate.com/Tcl

--
Jeff Hobbs The Tcl Guy
Senior Developer http://www.ActiveState.com/
Tcl Support and Productivity Solutions

Bryan Oakley

unread,
Dec 3, 2002, 10:49:21 AM12/3/02
to
Ronny Frevert wrote:
> Hi all,
>
> I took an example (see below) out of a Tcl/Tk book to create a
> scrollable form using the canvas widget. Now the problem in my script
> is, that the red frame "$win2.vport.form" covers only around 60 percent
> of the blue canvas "$win2.vport" area. Now I'm looking for a command to
> expand this frame inside this canvas widget. I changed also the anchor
> in line xy to east, but the frame everytime occurs on the left. All
> widgets inside this frame are expanded and only if I broad the widgets
> inside, the frame "frame $win2.vport.form" will broaden too. Has anyone
> an idea what could be wrong or which command could help?

The reason the frame only expands if the internal widgets expands is
that "propagation" is turned on. "propagation" (or "geometry
propagation") means that the children control the size of the parent.

If you want the frame to be a specific size, turn propagation off. Both
pack and grid have similar syntax: (pack/grid) propagate .some.frame 0.
Once you do this, you can use the configure subcommand to make the frame
any size you want.

The other piece of the puzzle may be to put a <Configure> binding on the
canvas. When the canvas resizes the binding will fire and you can then
resize the frame to match the width and/or height of the canvas. This
way, if the canvas grows wider than the frame the frame will
automatically grow appropriately.


Ronny Frevert

unread,
Dec 4, 2002, 5:04:50 AM12/4/02
to
Hi Brian,

> The reason the frame only expands if the internal widgets expands is
> that "propagation" is turned on. "propagation" (or "geometry
> propagation") means that the children control the size of the parent.

> If you want the frame to be a specific size, turn propagation off. Both

> pack and grid have similar syntax: (pack/grid) propagate .some.frame 0.
> Once you do this, you can use the configure subcommand to make the frame
> any size you want.
>
> The other piece of the puzzle may be to put a <Configure> binding on the
> canvas. When the canvas resizes the binding will fire and you can then
> resize the frame to match the width and/or height of the canvas. This
> way, if the canvas grows wider than the frame the frame will
> automatically grow appropriately.

I changed the part of code (please see below) and now the frame doesn't
appear anymore. The first problem is that the frame only appears if I add
the "height" -option to the configure command. But if I add this, the
scrollbar becomes senseless! The second problem is that "winfo width
$win2.vport" always (!) gives a value of "1" back (if I change "set abc" to
"puts" of course). Do you have any idea? This "frame inside canvas stuff" is
confusing me more and more :-). Putting line y into line x after <Configure>
also do not help!

Thank you and Regards,
Ronny

proc scrollform_create {win2} {

set abc 800

frame $win2 -class Scrollform

scrollbar $win2.sbar -command "$win2.vport yview"
pack $win2.sbar -side right -fill y

canvas $win2.vport -yscrollcommand "$win2.sbar set" -bg blue


pack $win2.vport -side top -fill both -expand true

bind $win2.vport <Configure> "set abc [winfo width $win2.vport]" /// line
x

frame $win2.vport.form -bg red


$win2.vport create window 0 0 -anchor nw -window $win2.vport.form

pack propagate $win2.vport.form 0
$win2.vport.form configure -width $abc /// line y

Bryan Oakley

unread,
Dec 4, 2002, 12:30:19 PM12/4/02
to
Ronny Frevert wrote:
>
> I changed the part of code (please see below) and now the frame doesn't
> appear anymore.

This falls under the category of "you can't have your cake and eat it
too". If you turn propagation off it is up to you to determine the
width/height of the frame. Put another way, it is having propagation
turned on that gives the wonderous effect of frames auto-sizing to fit
their children. 99.9% of the time this is exactly the Right Thing To Do.
Welcome to the other .1%

The first problem is that the frame only appears if I add
> the "height" -option to the configure command. But if I add this, the
> scrollbar becomes senseless! The second problem is that "winfo width
> $win2.vport" always (!) gives a value of "1" back (if I change "set abc" to
> "puts" of course). Do you have any idea? This "frame inside canvas stuff" is
> confusing me more and more :-).

This is why Jeff Hobbs (I think...) recommended you go with a
pre-packaged solution (eg: bwidgets). It's not a particularly simple
problem to solve.

The solution I use is to first leave propagation on. This lets the frame
auto-size. Then set a binding on <Configure> for the canvas, and the
first time that you need to programatically set the size of the frame to
fit the canvas, turn propagation off. The trick is to remember what size
the frame wants to be before you turn propagation off. Then, when the
<Configure> event fires, make sure you never resize the frame below this
minimum preferred size.

Sorry I don't have time to give an example; I just don't have any handy
and don't have the time to make one up right now.

You should seriously consider going with bwidgets or some other
extension that provides this functionaliity. Even if you don't want to
use the extention you can at least look at how it solves this problem.

0 new messages