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

How to display multi-lines in a table

44 views
Skip to first unread message

Cecil Westerhof

unread,
Dec 20, 2017, 5:44:05 AM12/20/17
to
I have collected a lot of Dutch proverbs. I want to write a Tcl
application to maintain them, but they are multi-lined. So how would I
display something like:
|------------------------------------|
|Als apen hoger klimmen willen,
|ziet men gauw hun blote billen.

Als de berg niet tot Mohammed komt,
zal Mohammed tot de berg gaan.

Als de ene hand de ander wast
worden ze allebei schoon.

Als de herder verdwaalt
dolen de schapen.

Als de kat van huis is,
dansen de muizen op tafel.

Als de nood het hoogste is,
is de redding nabij.

Als de vos de passie preekt,
boer, let op uw ganzen.

Als de wijn is in de man,
is de wijsheid in de kan.

Als er een schaap over de dam is,
volgen er meer.

Als hadden geweest is,
is hebben te laat.

Als het getij verloopt,
verzet men de bakens.

Als het kalf verdronken is,
dempt men de put.

Als het schip lek is,
gaan de ratten van boord.

Als het water zakt,
dan kraakt het ijs.

Als je hem een vinger geeft,
neemt hij de hele hand.
--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

Cecil Westerhof

unread,
Dec 20, 2017, 5:59:05 AM12/20/17
to
Something went wrong and the message was send while I was still
editing it. :'-(

I have collected a lot of Dutch proverbs. I want to write a Tcl
application to maintain them, but they are multi-lined. So how would I
display something like:
|-------------------------------------|
| Als apen hoger klimmen willen, |
| ziet men gauw hun blote billen. |
|-------------------------------------|
| Als de berg niet tot Mohammed komt, |
| zal Mohammed tot de berg gaan. |
|-------------------------------------|
| Als de ene hand de ander wast |
| worden ze allebei schoon. |
|-------------------------------------|
| Als de herder verdwaalt |
| dolen de schapen. |
|-------------------------------------|
| Als de kat van huis is, |
| dansen de muizen op tafel. |
|-------------------------------------|
| Als de nood het hoogste is, |
| is de redding nabij. |
|-------------------------------------|
| Als de vos de passie preekt, |
| boer, let op uw ganzen. |
|-------------------------------------|
| Als de wijn is in de man, |
| is de wijsheid in de kan. |
|-------------------------------------|
| Als er een schaap over de dam is, |
| volgen er meer. |
|-------------------------------------|
| Als hadden geweest is, |
| is hebben te laat. |
|-------------------------------------|
| Als het getij verloopt, |
| verzet men de bakens. |
|-------------------------------------|
| Als het kalf verdronken is, |
| dempt men de put. |
|-------------------------------------|
| Als het schip lek is, |
| gaan de ratten van boord. |
|-------------------------------------|
| Als het water zakt, |
| dan kraakt het ijs. |
|-------------------------------------|
| Als je hem een vinger geeft, |
| neemt hij de hele hand. |
|-------------------------------------|
| Al te goed is buurmans gek. |
|-------------------------------------|

So the height of the rows is fitting for the amount of data that has
to be displayed.

One cave-cat: there will be other rows also, so the height should
accommodate the highest of the row.

nemethi

unread,
Dec 20, 2017, 9:14:54 AM12/20/17
to
You can just insert the proverbs into a text widget and separate them
with empty lines, but for a fancier and more user-friendly display you
will need a different widget. Here is an example using the Tablelist
package:

#!/usr/bin/env wish

package require tablelist
wm title . "Proverbs"

# Create a vertically scrolled tablelist widget
# with 1 dynamic-width column and optimal width
set tbl .tbl
set vsb .vsb
tablelist::tablelist $tbl -columntitles {"Proverbs"} -spacing 5 \
-stripebackground #f0f0f0 -yscrollcommand [list $vsb set] -width 0
scrollbar $vsb -orient vertical -command [list $tbl yview]

# Populate the tablelist widget
$tbl insert end \
[list "Als apen hoger klimmen willen,\nziet men gauw hun blote
billen."] \
[list "Als de berg niet tot Mohammed komt,\nzal Mohammed tot de
berg gaan."] \
. . .
[list "Als je hem een vinger geeft,\nneemt hij de hele hand."] \
[list "Al te goed is buurmans gek."]

set btn [button .btn -text "Close" -command exit]

# Manage the widgets
grid $tbl -row 0 -column 0 -sticky news
grid $vsb -row 0 -column 1 -sticky ns
grid $btn -row 1 -column 0 -columnspan 2 -pady 10
grid rowconfigure . 0 -weight 1
grid columnconfigure . 0 -weight 1

--
Csaba Nemethi http://www.nemethi.de mailto:csaba....@t-online.de

Cecil Westerhof

unread,
Dec 20, 2017, 11:14:07 AM12/20/17
to
Not really, because I have to select the individual entries.
That looks exactly like what I need. Needed to install some extra
packages, but that is not a big problem. ;-)

Thanks.


Changed it to filling it from the database and that works like a
charm. Now I have to create some functionalities.

Cecil Westerhof

unread,
Dec 20, 2017, 12:28:06 PM12/20/17
to
There is one problem: when I resize the window, the elements are not
resized. What need I to do to let the elements resize also?

Rich

unread,
Dec 20, 2017, 4:04:29 PM12/20/17
to
Cecil Westerhof <Ce...@decebal.nl> wrote:
> Something went wrong and the message was send while I was still
> editing it. :'-(
>
> I have collected a lot of Dutch proverbs. I want to write a Tcl
> application to maintain them, but they are multi-lined. So how would I
> display something like:
> |-------------------------------------|
> | Als apen hoger klimmen willen, |
> | ziet men gauw hun blote billen. |
> |-------------------------------------|
> | Als de berg niet tot Mohammed komt, |
> | zal Mohammed tot de berg gaan. |
> |-------------------------------------|
[snip]
> So the height of the rows is fitting for the amount of data that has
> to be displayed.
>
> One cave-cat: there will be other rows also, so the height should
> accommodate the highest of the row.

If you want a textual dump just like the above, look at the 'report'
module in tcllib. When combined with the 'matrix' data structure
module you can use 'report' to output a text delimited layout like what
you have above.

nemethi

unread,
Dec 21, 2017, 6:50:25 AM12/21/17
to
You mean probably that the width of the single column is not adapted to
the new width of the tablelist window. Why is this a problem? The
initial column width is just large enough to hold all the proverbs, and
the initial width of the widget is just large enough to hold the single
column. IMHO, a better solution would be to provide a horizontal
scrollbar, too.

If you stick to the automatic resizing of the column, you can achieve it
as follows:

bind $tbl <Configure> {
set width %w
incr width -20 ;# actually, this value should be computed
if {$width > 0} {
%W columnconfigure 0 -width -$width
0 new messages