gri6507 has asked for the wisdom of the Perl Monks concerning the following question:

I was trying use use a Labeled BrowseEntry like so:
use strict; use Tk; use Data::Dumper; my $active_text_color = "#000000"; my $bgcolor = "#FFFFFF"; my $text_font = 'helvetica 12'; my $mw = MainWindow->new(); my $f = $mw->BrowseEntry(-label=>'Try Me:', -labelPack=>[qw(-side left + -anchor w)],-labelFont=>$text_font, -labelForeground=>$active_text_c +olor, -labelBackground=>$bgcolor, -width=>5, -choices=>[qw(A B C)])-> +pack(-side=>'left', -expand=>1, -fill=>'x'); print Dumper(\$f); MainLoop;
and what I get is some kind of an empty space above my Label and browseEntry. That is playing havoc in my GUI right now and for the life of me, I can't figure out where this extra space is coming from. Does anyone know?

Replies are listed 'Best First'.
Re: Tk::BrowseEntry question
by eserte (Deacon) on Dec 16, 2006 at 11:47 UTC
    This problem is caused by an unfortunate auto-delegation implementation in Tk. Tk::BrowseEntry inherits from Tk::Frame and delegates some options to the internal Tk::LabEntry subwidget. Unfortunately Tk::Frame itself uses some of the -label* options itself and auto-creates a Label. So under some circumstances (as in yours) you get an unwanted Label widget.

    It seems that the correct solution would be patching Tk::BrowseEntry to pass all -label* options to the Tk::LabEntry subwidget:

    --- Tixish/BrowseEntry.pm (revision 1396) +++ Tixish/BrowseEntry.pm (local) @@ -26,7 +26,17 @@ sub ListboxWidget { "Listbox" } sub Populate { my ($w, $args) = @_; + my %labelArgs; + while(my($k,$v) = each %$args) { + $labelArgs{$k} = $v; + delete $args->{$k}; + } + $w->Tk::Frame::Populate($args); + + while(my($k,$v) = each %labelArgs) { + $args->{$k} = $v; + } # entry widget and arrow button my $lpack = delete $args->{-labelPack};

    Another solution would be to not use any of the -label* options when constructing the BrowseEntry, but configure the subwidget directly (the Subwidget name is "entry").

    Or just use the optiondb? $mw->optionAdd("*BrowseEntry.Entry.background", $bgcolor, "startupFile"); ...

Re: Tk::BrowseEntry question
by Popcorn Dave (Abbot) on Dec 16, 2006 at 06:11 UTC
    Changing the bg color shows it's your background, so I think it may stem from the fact you haven't defined a window size in this snippet and that may be what's causing your problem. I've never used this particular Tk widget, but that's where I'd start looking.

    Revolution. Today, 3 O'Clock. Meet behind the monkey bars.