Two text widgets side by side? 
Author Message
 Two text widgets side by side?

What's wanted is (as usual) a bit more complicated, but if the "2" case
could be made to work, the rest would probably fall into place.  But
I don't seem to be able to stumble across the incantation that will
make the "2" case work ...

The problem is:  Create a window with two text widgets side by side,
and which resize themselves to when the user stretches the outer window,
each text widget getting (about) 1/2 the window's width.  

I've actually been trying it with the text windows inside frames, so
that I can add scrollbars, but that's probably not important here.
Because of the problems with pixel vs char widths, I suspect that the
solution will probably involve putting each text widget inside its
own frame, but I'm not entirely sure of this.

It seems like it oughta be easy.  Packing a single text widget into
a window with -expand 1 -fill both works just fine, as does packing
a text widget inside a frame inside a toplevel. But attempts to do
it  with two of them just don't seem to work.  Either one takes up
the entire width, with the other "off-screen", or only one resizes
itself, or the resizing is ignored, or ...

I've played around with all sorts of schemes involving bind $w <Configure>,
to little avail.  I can get all sorts of info about how the widgets are
configured, but sending them "config -width ..." commands usually seems
to have no effect whatsoever.  (I suspect that the "-fill x" has taken
precedence, but I can't find any evidence in TFM pages.)

Is there a working example lying about somewhere that I (and AltaVista)
can't find it?  Is this mentioned in some FAQ that I (and AltaVista) also
can't find?

(I've been using both 7.4/4.0 and 8.0; my non-working examples seem to fail
in the same way with both.)



Fri, 01 Dec 2000 03:00:00 GMT  
 Two text widgets side by side?

John,

The problem is that the text widgets have a fairly large default
width.  So the first text widget will only shrink to this size, and
then it won't shrink any further till the other text widget has
totally disappeared.

However, something like this will work:

text .t1 -width 0
text .t2 -width 0
wm geometry . 400x400
pack .t1 .t2 -side left -fill both -expand 1

Then as the user stretches the window, the two text widgets will split
the space between them evenly.  You have to set the geometry of
. explicitly, because otherwise the window will come up with 0 width
when it shrinkwraps around the contained elements.

Hope this helps...

Jim.

++==++==++==++==++==++==++==++==++==++==++==++==++==++==++==++==++==++==++

Cygnus Solutions Inc.

--



Fri, 01 Dec 2000 03:00:00 GMT  
 Two text widgets side by side?

Quote:

> What's wanted is (as usual) a bit more complicated, but if the "2" case
> could be made to work, the rest would probably fall into place.  But
> I don't seem to be able to stumble across the incantation that will
> make the "2" case work ...

[snip]

There was a thread about this last month, if I recall. Try this: set the
width and height of the widgets to 0. What is happening is when you
resize the window smaller than will hold both widgets, the packer will
try to minimize the damage by only shrinking one window smaller than its
requested size. So one will shrink to nothing before the other is
shrunk.

    text .t1 -width 0 -height 0
    text .t2 -width 0 -height 0
    pack .t1 .t2 -side left -fill both -expand y

--
Bryan Oakley
ChannelPoint, Inc.



Fri, 01 Dec 2000 03:00:00 GMT  
 Two text widgets side by side?

Quote:

> The problem is:  Create a window with two text widgets side by side,
> and which resize themselves to when the user stretches the outer window,
> each text widget getting (about) 1/2 the window's width.
        <snip>
> I've played around with all sorts of schemes involving bind $w <Configure>,
> to little avail.  I can get all sorts of info about how the widgets are
> configured, but sending them "config -width ..." commands usually seems
> to have no effect whatsoever.  (I suspect that the "-fill x" has taken
> precedence, but I can't find any evidence in TFM pages.)

Why don't you use the grid geometry manager?  It is designed
specifically to maintain these kind of layouts.  You will also
not need extra frames to lay out the scrollbars.

Cheers,
        Nat.

--
+------------------------------------------+---------------------+
| Name:   Nat Pryce MEng ACGI              | Dept. of Computing, |

| Tel:    +44 (0)171 594 8394              | 180 Queen's Gate,   |
| Fax:    +44 (0)171 581 8024              | London SW7 2BZ,     |
| WWW:    http://www-dse.doc.ic.ac.uk/~np2 | United Kingdom      |
+------------------------------------------+---------------------+



Fri, 01 Dec 2000 03:00:00 GMT  
 Two text widgets side by side?

Quote:

> However, something like this will work:

> text .t1 -width 0
> text .t2 -width 0
> wm geometry . 400x400
> pack .t1 .t2 -side left -fill both -expand 1

Yeah; that actually does work.  Thanks.  I don't think I'd have
ever guessed that setting the width to zero was the answer.  And
grovelling around in "man n text" doesn't seem to turn up any clue
as to what's going on here.  I guess this is something that can
only be learned by asking in the newsgroup.  (Or is it hidden in
some FAQ somewhere that I couldn't find? ;-)

On to the next question ...



Sun, 03 Dec 2000 03:00:00 GMT  
 Two text widgets side by side?

   |> What's wanted is (as usual) a bit more complicated, but if the "2" case
   |> could be made to work, the rest would probably fall into place.  But
   |> I don't seem to be able to stumble across the incantation that will
   |> make the "2" case work ...

   |> The problem is:  Create a window with two text widgets side by side,
   |> and which resize themselves to when the user stretches the outer window,
   |> each text widget getting (about) 1/2 the window's width.  

The following should do it:

% pack [text .t1 -wid 0] -fill both -expand 1 -side left
% pack [text .t2 -wid 0] -fill both -expand 1 -side left

I think the key is to set the initial width of the text widgets to
zero, then set the parenting window to the width you want.

Good luck,
--

############################################################
#  John Vella            #  Job  : Software Development    #

#  Mentor Graphics Corp. #  Phone: (503) 685 - 1170        #
#  Wilsonville, OR       #  Fax  : (503) 685 - 1461        #
############################################################



Sun, 03 Dec 2000 03:00:00 GMT  
 Two text widgets side by side?

Quote:

> Why don't you use the grid geometry manager?  It is designed
> specifically to maintain these kind of layouts.  You will also
> not need extra frames to lay out the scrollbars.

Good idea.  In fact, that was what I first tried.  It failed
because of the simple fact that the text widgets refused to
resize themselves to match the gridding.  I tried a simple test
case with four text widgets gridded into two rows and two
columns of a frame widget, and found that when I resized the
outermost "." window, the text widgets retained their sizes,
and the rightmost column wasn't visible.

In any case, I sorta like frames, because I can say "-bd 5"
and make the borders visible on the screen.  The grid command
doesn't seem to have anything like this.  Or does it, and I
just can't guess what it's called?

Also, the apps that I'm looking at require that I embed a
number of text widgets inside either an outer text widget
or an outer canvas widget.  If you want a model, think of
the HTML <TABLE> construct (which is a special case of what
I'm trying to do).  You have an outer "document" (text or
canvas), which is populated by a number of thingies.  Some
of those thingies are themselves text or canvas widgets,
and they need to be resized to fit inside the outer widget,
and without hiding the other thingies.

I've also grabbed the tkTable stuff, and I'm trying to make
sense of it.  Sure is complicated.  And there's a lot of
code there for which my first reaction is "Hmmm ... Is this
really tcl? Yup, the interpreter seems to accept it. Wonder
what that strange syntax means?"



Mon, 04 Dec 2000 03:00:00 GMT  
 Two text widgets side by side?

Quote:


> > Why don't you use the grid geometry manager?  It is designed
> > specifically to maintain these kind of layouts.  You will also
> > not need extra frames to lay out the scrollbars.

> Good idea.  In fact, that was what I first tried.  It failed
> because of the simple fact that the text widgets refused to
> resize themselves to match the gridding.  I tried a simple test
> case with four text widgets gridded into two rows and two
> columns of a frame widget, and found that when I resized the
> outermost "." window, the text widgets retained their sizes,
> and the rightmost column wasn't visible.

Did you set the row and column weights?  The weights specify how
to allocate extra space to rows and columns (or how to shrink
rows and columns to fit them into smaller space).

--
+------------------------------------------+---------------------+
| Name:   Nat Pryce MEng ACGI              | Dept. of Computing, |

| Tel:    +44 (0)171 594 8394              | 180 Queen's Gate,   |
| Fax:    +44 (0)171 581 8024              | London SW7 2BZ,     |
| WWW:    http://www-dse.doc.ic.ac.uk/~np2 | United Kingdom      |
+------------------------------------------+---------------------+



Mon, 04 Dec 2000 03:00:00 GMT  
 Two text widgets side by side?

Quote:


> > Why don't you use the grid geometry manager?  It is designed
> Good idea.  In fact, that was what I first tried.  It failed
> because of the simple fact that the text widgets refused to
> resize themselves to match the gridding.  I tried a simple test

This sounds like a problem of row/columnconfigure with -weight.
While the grid geom manager is more powerful than pack, it is
also more complicated to set up some precise layout requirements.
However, once learned and understood, it is a fairly easy
piece of Tk to remember what does what.

Quote:
> Also, the apps that I'm looking at require that I embed a
> number of text widgets inside either an outer text widget
> or an outer canvas widget.  If you want a model, think of

This sounds like something that is 99% possible by the Tk text
widget.  The other 1% might be a real pain to handle though.

Quote:
> I've also grabbed the tkTable stuff, and I'm trying to make
> sense of it.  Sure is complicated.  And there's a lot of

What strange syntax were you referring to?  I've done a lot of
work since first taking it over to make it look more Tk-like.
v2.x has so many features though, that it is becoming hard to
decide where to stick new things in.  Suggestions are always
accepted, but I don't think this is the answer for your above
particular problem.

--
    Jeffrey Hobbs               "I'm really just a Tcl-bot"
    jeff.hobbs at acm.org | Jeffrey.Hobbs at oen.siemens.de



Tue, 05 Dec 2000 03:00:00 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. Lines Side by Side?

2. Class side vs Instance Side??

3. smalltalk - java side by side

4. smalltalk - java side by side

5. Printing group footers side-by-side

6. Report details side by side

7. New MVS REXX Utility: Compare partitioned datasets side-by-side - pdsmatch.zip (1/1)

8. client side or server side scripting- new web user

9. Is it possible to concatenate two text files side by side?

10. Two-side printing

11. HP2200D - two-sided printing

12. Two sided polygons with different colors ???

 

 
Powered by phpBB® Forum Software