I can't reproduce the problem with the colors, but I can for height/width. It isn't so much a problem as a misunderstanding of the Scrolled composite.

When you use it you are delegating responsibility for displaying the 'scrolled' subwidget to the Scrolled composite. Scrolled allows you to initialize the settings (height/width) of the enclosed subwidget up until all events have been processed by MainLoop the first time.

So the following will work:

Updated: caught and corrected a typo in the first example. Added the qw to the configure method params.

use Tk; use Tk::SearchEntry; my $main = MainWindow->new; $w = $main->Scrolled( 'SearchEntry', #custom widget -scrollbars => '', -width => 70, -height => 1, -bg => "#ffffff", )->grid( -sticky => 'w', -row => 1, -column => 0, -padx => 5, -pady => 1, ); $w->configure(qw/-height 10 -bg blue -fg white/); MainLoop;
But the next, will not:
use Tk; use Tk::SearchEntry; my $main = MainWindow->new; $w = $main->Scrolled( 'SearchEntry', #custom widget -scrollbars => '', -width => 70, -height => 1, -bg => "#ffffff", )->grid( -sticky => 'w', -row => 1, -column => 0, -padx => 5, -pady => 1, ); $main->Button( -text => "Change", -command => sub { $w->configure(-width => 10, -height => 10); })->grid; MainLoop;

This is because by the time the Button has been pressed, sizing control has been yielded to Scrolled. You can take it back using the packPropagate method. Notice how the first Change button makes the change, but then when the second Change button tries, it cannot. The size is being passed, it's just not having any visible effect.

use Tk; use Tk::SearchEntry; my $main = MainWindow->new; $w = $main->Scrolled( 'SearchEntry', #custom widget -scrollbars => '', -width => 70, -height => 1, -bg => "#ffffff", )->grid( -sticky => 'w', -row => 1, -column => 0, -padx => 5, -pady => 1, ); $main->Button( -text => "Change", -command => sub { ## allow subwidget to exert control over the size $w->packPropagate(1); $w->configure(-width => 10, -height => 10); ## This line resets it back, but only after ## the change has taken place. You don't *have* ## to reset packPropagate to 0, but be aware that ## it will reset itself, each time the widget is ## mapped. $w->afterIdle([$w, 'packPropagate', 0]); })->grid; $main->Button( -text => "Change2", -command => sub { $w->configure(-width => 30, -height => 2); })->grid; MainLoop;

Another way I have dealt with this in the past is to enclose the Scrolled widget within another Frame, but set it up to expand/shrink as the parent frame resizes. Then I size the Frame instead of the Scrolled widget.

HTH,

Rob

In reply to Re^3: Perl/Tk Scrolled issue by rcseege
in thread Perl/Tk Scrolled issue by artemave

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.