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

I have a Perl TK script working nicely with several Listboxes but I have not been able to find any way to set a default selection from the list once the list has been populated. I have buttons to call subs based on the user's selection(s) but I want to prevent not having anything selected. Any ideas???

Replies are listed 'Best First'.
Re: How to set a default Listbox selection
by kennethk (Abbot) on Feb 19, 2016 at 17:31 UTC
    If you'd like an element to be selected, then you should select it. From Tk::Listbox:
    $listbox->selectionSet(first, ?last?)

    Selects all of the elements in the range between first and last, inclusive, without affecting the selection state of elements outside that range.


    #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

      Thanks! That was surprisingly easy! I tried that (and other methods) multiple times the other day with no luck. I must have been missing something in the syntax or just had a typo.