in reply to Re: Perl/Tk Scrolled issue
in thread Perl/Tk Scrolled issue

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.

Replies are listed 'Best First'.
Re^3: Perl/Tk Scrolled issue
by rcseege (Pilgrim) on Aug 20, 2006 at 19:38 UTC

    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.
        Misunderstanding of Scrolled is partly caused by the lack of documentation.

        Yeah - I completely understand. One of the problems with Perl/Tk IMO, is that it includes so much, it's tough to stay on top of it all and keep up with the Documentation, Patches to minor widgets, etc. The effort isn't all that distributed for such a large distro.

        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.

        There are quite a few resources out there for Perl/Tk. Admittedly, a few of them are showing their age a bit... There is a core set of resources that I go back to time and time again, and you might have found the answer in the first resource. I completely agree that it would have been nice if this "gotcha" had been pointed out in the docs, but what can you do? I hope the abbreviated list below helps.

        comp.lang.perl.tk and pTk mailing list
        I include these together, since most of what is posted to the pTk mailing list gets mirrored to c.l.p.tk. There are a core group of folks who have been answering questions in these forums for years. Even if you're not interested in posting, the archives serve as an invaluable resource. http://groups.google.com/group/comp.lang.perl.tk is one of the first places I go when I have a question.
        Mastering Perl/Tk, by Steve Lidie and Nancy Walsh
        You already mentioned this in your post. I felt completely comfortable with Perl/Tk before I got the book, and I figured it would be a good reference, but I was amazed at the amount of content that I hadn't seen before. It's worth mentioning that Steve has a site where he links to other Perl/Tk resources. He also contributes to the pTk mailing list.
        Perl/Tk Org - http://www.perltk.org
        Ala Qumsieh, a frequent contributer to ptk/c.l.p.tk maintains this site which contains scripts, articles, and other information. (It looks like the layout has changed again since the last time I was there... nice)
        The Source
        When I started out with Perl/Tk I spent a lot of time in the source code, like a kid taking something apart to see how it worked. The source served as a great spot to learn how bindings were handled and some obscure tricks. When I came to something I didn't understand, I'd search the internet for it or post a question to one of online forums. I would experiement with modifying existing widgets to see what would happen. It was fun and I learned a lot. You might check out the widget demo that comes with the distro.
        Other resources
        • ActiveState's Documentation - which is really just the POD, but organized for easy browsing.
        • The Perl/Tk FAQ - maintained by Cameron Laird. Contains loads of other Perl/Tk resources, code snippets, history... and lots of dead links, but still fun to poke through.
        • Perl month archives featured articles on Perl including a few on Perl/Tk by Steve Lidie and Slaven Rezic (Another frequent pTk contributor).
        • http://www.perl.com - You can find articles on Perl/Tk here.

        These represent the resources that come to mind the quickest, and I know I've left out many others. There are several books that have coverage of Perl/Tk (which you can find in the FAQ, along with other resources, provided the links are still valid). In addition, I end up turning to Tcl/Tk sites, X Windows references for information on Events, MSDN and other Win32 sites for Windows specific information. This should be a pretty decent sampling.

        Rob