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

Greetings, I coded two listboxes in one toplevel, how can I make the selected elements remain highlighted even if focus had been lost for that listbox? What happens is that I can select from one but not both. Need your inputs. Thanks
  • Comment on maintaining selected elements in 2 Listboxes

Replies are listed 'Best First'.
Re: maintaining selected elements in 2 Listboxes
by graff (Chancellor) on Oct 25, 2002 at 05:54 UTC
    You should look at the description of "exportSelection" in the Tk::options man page -- although this may only be relevant if you're working in an X-Windows environment. If you're working with MS-Windows, I'm not sure how this plays out.

    If you are using X-Windows, note that the X paste buffer can only work with one contiguous string at a time, and there is no way around this. That's why selecting one string will always deselect any other string -- except for Tk widgets where "exportSelection" is false, and in those cases, the highlighted string will stay highlighted when you select something else, but you won't be able to paste it anywhere.

    Well, maybe there's a way to create or locate an "alternate" paste buffer, other than the "standard" X paste buffer that is normally manipulated with mouse buttons. This would be easy within the scope of a single Perl/Tk app, but more challenging across independent apps (think "inter-process communication").

    I'm not sure, but I think that on MS-Windows, you have to specifically request that a highlighted string be copied into the window-manager's paste buffer in order to make it paste-able into another window. But again, only one contiguous string can be selected at a time for this sort of copying; (and I don't even know whether or not this is part of your question).