in reply to Perl/Tk Scrolled issue

Not all widgets can be scrolled, and Tk::SearchEntry certainly is not a widget I have come across, neither is it on CPAN. Is it a mega-widget of your own creation? If so it might help us to see its code.

jdtoronto

Replies are listed 'Best First'.
Re^2: Perl/Tk Scrolled issue
by artemave (Beadle) on Aug 20, 2006 at 12:08 UTC
    This one is certainly Scrolled. It appeares as Scrolled. No problems.
    Here is the code:
    use base qw/Tk::Derived Tk::TextUndo/; Construct Tk::Widget 'SearchEntry'; sub ClassInit { my($class, $mw) = @_; $class->SUPER::ClassInit($mw); $mw->bind($class, '<Control-a>', 'selectAll'); $mw->bind($class, '<Key-Tab>', sub { $_[0]->focusNext; Tk->break; +}); } sub Populate { my($self, $args) = @_; $self->menu(undef); }
    Artem.

      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
        Thank you, Rob.

        That really helped. As well as your explanation gave me some understanding of why it works this way.

        Misunderstanding of Scrolled is partly caused by the lack of documentation. I didn't find anything on this niether in Perl/Tk pod nor in Mastering Perl/Tk.
        I'd appreciate if you point me some usefull sources of Perl/Tk wisdom.

        Artem.
Re^2: Perl/Tk Scrolled issue
by tanyeun (Sexton) on Aug 20, 2006 at 12:12 UTC
    agreed with jdtoronto
    my computer can't locate Tk::SearchEntry on
    either:
    perl v5.6.1 built for MSWin32-x86(Active Perl)
    ->Tk804.027
    or
    perl v5.8.7 built for cygwin
    ->Tk800.024
      That's my custom widget.
      See the code above in the thread.
      Artem.