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

Hi, I have a combobox written using Tk::BrowseEntry. The problem I am facing is that everytime the arrow on the combobox is pressed the data shown on the list is repeated. Is there any command or option in order to prevent this from happening? The statement I have used is

$child = $parent->BrowseEntry(-label => " ComboBox " , -variable => \$var ,-listcmd => sub {subroutine} );

The subroutine is used to populate the list shown in the combobox. Is there any other way to populate the values in a combo box dynamically?

Replies are listed 'Best First'.
Re: combobox in perl/Tk
by lamprecht (Friar) on Oct 07, 2009 at 11:51 UTC
    Hi,

    If your data in the list gets repeated, maybe you forget to delete the entries before you insert the new items?
    The listbox used by Tk::BrowseEntry is a simple Tk::Listbox. It implements a tied interface which makes it possible to access and modify the Listbox content with simple array operations.
    See Tk::Listbox,
    Tk::BrowseEntry

    use strict; use warnings; use Tk; my $mw = tkinit; my $be = $mw->BrowseEntry->pack; my $l = $be->Subwidget('slistbox')->Subwidget('scrolled'); my @content; tie @content,'Tk::Listbox', $l; @content = qw/apple banana orange /; $mw->Button(-text => 'change', -command => sub{ @content = qw/Paris Tokyo London /; }, )->pack; MainLoop();

    update: added example


    Cheers, Christoph

      Hey Christoph, Thanks a ton. I wasted half a day on this!