in reply to Tk::ListBox questions

This works, use the listvariable option instead of insert.
#!/usr/bin/perl use strict; use Tk; my $lst_properties; my $chk_options; my $chkoptions; my $MainWindow; &maingui; sub maingui { $MainWindow = MainWindow->new(-title=>'Listbox'); my @properties = ("People","Animals","Aliens","Meat", "Fruit","Vegies","Dairy","Pultry", ); $chk_options = $MainWindow -> Checkbutton ( -anchor=>'nw', -justify=>'left',-relief=>'flat', -indicatoron=>1,-text=>'Additional Criteria', -variable=>\$chkoptions, -state=>'normal', -command=>\&Additional_Criteria ) -> grid(-row=>1,-column=>0,-pady=>5); $lst_properties= $MainWindow -> Scrolled ( 'Listbox', -selectmode=>'single', -relief=>'sunken', -scrollbars=>'osoe', -width=>50, -listvariable=>\@properties, -state=>'disabled' ); $lst_properties -> grid(-row=>5,-column=>1,-pady=>3); MainLoop; } sub Additional_Criteria { #code her to test if check box is selected or not if ($chkoptions) { print "Enable\n"; $lst_properties->configure(-state=>'normal'); } else { print "Disable\n"; #Code here to DISABLE ListBox $lst_properties->configure(-state=>'disabled'); } }

I'm not really a human, but I play one on earth. Cogito ergo sum a bum

Replies are listed 'Best First'.
Re^2: Tk::ListBox questions
by g_speran (Scribe) on Mar 17, 2008 at 14:39 UTC
    Hello Zentara,
    This worked! I definatly like the idea of "listvaraibles".
    Thanks for your assistance
      Yeah, the nice thing about an array as a list variable, is you can just modify the array any way you want, and it will be automatically updated in the listbox. So you can sort, remove, or splice elements into the array at any position, and the list will show it. Trying to modify the list itself is quite abit trickier, since you need to deal with the indices of the listbox.

      I'm not really a human, but I play one on earth. Cogito ergo sum a bum