Your code which I simplified below works fine.
How would @list get modified? That is the real question here.
You don't show any code for that.
Do you want a right-click menu to add/delete? Do you want an Add/Delete menu bar?
Adding a new element to the listbox means that
my @list = ( "a", "b", "c", "d", "e", "f" );
has been modified. Perhaps:
my @list = ( "a", "b", "c", "d", "e", "f","g" );
or perhaps ( "a", "b", "NEW", "c", "d", "e", "f" )
or perhaps ( "a", "b", "c")
I would be thinking of just deleting all element in the Listbox
and then re-insert the new elements from this modified list.
That is one way to change the contents of a Listbox.
It would be very helpful if you could describe what the user is
going to do that results in a different displayed Listbox contents?
I think there is a wrong thought model here. If you change the Listbox,
then you know you did that. Call the update Listbox routine. Or perhaps
the window with list box, fetches new data every time is is displayed.
My last thought would be a timed update every x seconds.
=================================
use strict;
use warnings;
use Tk;
my $mw = MainWindow->new();
my $lbox = $mw->Listbox()->pack();
my @list = ( "a", "b", "c", "d", "e", "f" );
$lbox->insert('end', @list );
$lbox->selectionSet('2'); #default starting selection in the box,"c"
$lbox->bind('<<ListboxSelect>>', sub{warn "new ListBox element selecte
+d!\n"} );
MainLoop;
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.