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

I am trying to workaround what appears to be TK bug related to browseentry widgets.
What's happening is that when I populate with a long list of choices, then repopulate with a short list of choices, then go back to a long list of choices the scrollbar isn't updating and it appears that I can't scroll.
However I can scroll if select one of the options with mouse1 down and drag down then the scroll slider widget reappears.
Also if reselect the drop down arrow then press the long list button again then it is corrected and scroll widget reappears.
I am trying to figure out how to update the widget so the scrollbar appears without having to destroy and recreate the widget or simulate an event to trigger the correct behavior.
I am using the following example:
#!/usr/bin/perl use strict; use Tk; use Tk::BrowseEntry; my $mw = MainWindow->new; # Mainwindow: sizex/y, positionx/y $mw->geometry("200x200+100+120"); my $shortlist = [qw(a b c d)]; my $longlist = [qw(a b c d e f g h i j k l m n o p r s t u w)]; &create_dropdown($mw); MainLoop; sub create_dropdown { my $mother = shift; # Create dropdown and another element which shows my selection my $dropdown_value; my $dropdown = $mother->BrowseEntry( -label => "Label", -variable => \$dropdown_value, -autolimitheight => 1 )->pack; $mother->Button( -text => "Short List", -command => sub{ $dropdown->configure(-choices => $shortlist)})->pack; $mother->Button( -text => "Long List", -command => sub{ $dropdown->configure(-choices => $longlist)})->pack; # Populate dropdown with values $dropdown->configure(-choices => $longlist, -autolimitheight => 1) +; return; }

Replies are listed 'Best First'.
Re: BrowseEntry scrollbar not updating
by TheForeigner (Initiate) on Nov 14, 2007 at 22:04 UTC
    I found a way to work WAY around it... there should be a better way, but after searching around, I couldn't find a simple solution. So I cheated by creating a new BrowseEntry and by using a Frame to keep it in the same place, the 'destroy' in there helps with memory management (so you're not creating hundreds of overlapping BrowseEntry's. Here's the code:
    use strict; use Tk; use Tk::BrowseEntry; my $mw = MainWindow->new; # Mainwindow: sizex/y, positionx/y $mw->geometry("200x200+100+120"); my $shortlist = [qw(a b c d)]; my $longlist = [qw(a b c d e f g h i j k l m n o p r s t u w)]; &create_dropdown($mw); MainLoop; sub create_dropdown { my $mother = shift; # Create dropdown and another element which shows my selection my $dropdown_value; my $dropdown; my $frame = $mother->Frame->pack; $dropdown = dropDown($dropdown,$frame,\$dropdown_value,$longlist); $mother->Button( -text => "Short List", -command => sub{$dropdown = dropDown($dropdown,$frame,\$dropdown_value,$sh +ortlist)})->pack; $mother->Button( -text => "Long List", -command => sub{$dropdown = dropDown($dropdown,$frame,\$dropdown_value,$lo +nglist)})->pack; return; } sub dropDown{ my ($oldDropdown, $frame,$dropdown_value,$options) = @_; $oldDropdown->destroy if $oldDropdown; my $dropdown = $frame->BrowseEntry( -label => "Label", -variable => $dropdown_value, -autolimitheight => 1, -choices => $options ); $dropdown->grid(-row=>1,-column=>1); $dropdown; }
Re: BrowseEntry scrollbar not updating
by zentara (Cardinal) on Nov 15, 2007 at 14:44 UTC
    What's happening is that when I populate with a long list of choices, then repopulate with a short list of choices, then go back to a long list of choices the scrollbar isn't updating and it appears that I can't scroll.

    Your first code seems to work for me, maybe you have a version/platform problem? I'm using Tk-804.027 on linux.The following code works fine for me, which is similar to your code. Maybe I don't understand your problem.

    #!/usr/bin/perl use strict; use Tk; use Tk::BrowseEntry; my $mw = MainWindow->new; # Mainwindow: sizex/y, positionx/y $mw->geometry("200x200+100+120"); my $shortlist = [qw(a b c d)]; my $longlist = [qw(a b c d e f g h i j k l m n o p r s t u w)]; my $reallonglist =[(1..100)]; # Create dropdown and another element which shows my selection my $dropdown_value = 42; my $dropdown = $mw->BrowseEntry( -label => "Label", -choices => [('')], -variable => \$dropdown_value, -autolimitheight => 1 )->pack; $mw->Button( -text => "Short List", -command => sub{ $dropdown->configure(-choices => $shortlist)})->pack; $mw->Button( -text => "Long List", -command => sub{ $dropdown->configure(-choices => $longlist)})->pack; $mw->Button( -text => "RealLong List", -command => sub{ $dropdown->configure(-choices => $reallonglist)})->pack; MainLoop;

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum
Re: BrowseEntry scrollbar not updating
by smaclach (Initiate) on Nov 15, 2007 at 20:08 UTC
    One of my colleagues found a simple solution: my $sl = $dropdown->Subwidget('slistbox'); $sl->{packysb} = 0; This forces the scrollbar to update appropriately.
Re: BrowseEntry scrollbar not updating
by Anonymous Monk on Sep 17, 2011 at 11:06 UTC
    This little trick will help you
    my $dropdown = $mother->BrowseEntry(...)->pack; $dropdown->Subwidget('slistbox')->configure(-scrollbars => "e");
    Bauldric