in reply to Re^2: Perl/Tk Scrolled issue
in thread Perl/Tk Scrolled issue
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.
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, ); $w->configure(qw/-height 10 -bg blue -fg white/); MainLoop;
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Perl/Tk Scrolled issue
by artemave (Beadle) on Aug 21, 2006 at 20:33 UTC | |
by rcseege (Pilgrim) on Aug 22, 2006 at 13:42 UTC |