in reply to Tk::JComboBox -choices option
#!/usr/bin/perl # http://perlmonks.org/?node_id=1192530 use strict; use warnings; use Tk; use Tk::JComboBox; my $main = MainWindow->new (-title => "Test JComboBox"); $main->geometry('+800+500'); my %TableHeaders = (1=>"English", 2=>"French", 3=>"German", 4=>"Undef", 5=>"Undef"); my $Language1; my $jcb = $main ->JComboBox( -textvariable => \$Language1, )->pack(); sub setchoices { $jcb->configure( -choices => [ map +{ -name => $TableHeaders{$_}, -value => $_ }, grep $TableHeaders{$_} ne 'Undef', sort keys %TableHeaders ] ); } setchoices(); $main->Button( -text => "Add Spanish as 6", -command => sub { $TableHeaders{6} = 'Spanish'; setchoices(); }, )->pack(); $main->Button( -text => "Add Undef as 7", -command => sub { $TableHeaders{7} = 'Undef'; setchoices(); }, )->pack(); MainLoop;
|
|---|