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

Monks,

I have a Tk::BrowseEntry widget populated with a list of values. When I call get('active') (since the get method is for the listbox 'sub-widget')on that widget with nothing selected, it returns the first item in the listbox. Quite obviously that item passes my quality checks since it was put in the list as a valid possibility

Is there a way I can keep it from doing this? Make the first Item in the list a null string that doesn't pass my checks? That's not quite elegant but it would work.

Any thoughts are appreciated,

Grygonos

Replies are listed 'Best First'.
Re: Tk::BrowseEntry -- get() with nothing selected
by eserte (Deacon) on Jun 04, 2004 at 16:51 UTC
    "active" is not "selected". It is the item which has the location cursor, according to the Tk::Listbox manpage. A listbox which has the focus will have such an item underlined, at least on X11 systems.

    You should rather use some of the *selection* methods.

      It's my understanding that the selection methods of Tk::Listbox modify the selection, and not return it. The curselection() method is not available by default in a Tk::BrowseEntry widget. Is there any way I can override the widget bindings so that the get method is defaulted to the Tk::Entry widget rather than the Tk::Listbox widget?

      Any help is appreciated,

      <edit>Well, I changed the BrowseEntry.pm to delegate to the entry widget rather than the scrolled listbox. However I would like to find a way to do it without trifling with the default bindings directly, (i.e. a code override rather than hard override)</edit>

        Use Subwidget, i.e. with $browseentry->Subwidget("subwidgetname")->method(...). The BrowseEntry documentation should provide the names of the advertides widgets.