Fellow Monks,

I have somewhat of a dillema with how to pack a Text widget into my Tk program. Let's say that I have a very simple GUI with a Text widget on top and a Frame on the bottom. The text widget must contain X characters of text at font Y and the window can be resized to size Z. In other words, the text in the Text widget can span a varying number of lines. What I'd like to do is to make the Text widget only as large as I need to given the number of lines that are in the widget at the time. So, what I have so far is:

my $t = $mw->Text(-height=>2, -font=>'helvetica 12')->pack(-side=>'top +', -expand=>'1', -fill=>'both'); $t->insert('end', "Blah " x 10); my $f = $mw->Frame(-background=>"#FF0000")->pack(-side=>'top', -expand +=>'1', -fill=>'both');

The problem that I have is that I need to make the Text widget large enough at all times to display all of the lines of text, even if the window is resized so that the text wraps around to, in this example, 3rd line. At the same time, I don't want the Text box to be any more lines than it has to be (and if possible not even expand when the window is resized and the text can fully fit in the alloted number of lines).

Basically, what I want is the ability to catch the MW_RESIZE events and use that as the trigger to get the line number of the 'end' character in the Text widget, so I could then configure the height accordingly. Is this possible in Tk?


In reply to Tk:Text resize dillema by gri6507

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.