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

Dear monks

I need a user to select from multiple dropdown menus always different values. In the example below I have 2 dropdoen menus (Tk::JComboBox) with language abbreviations. If the user picks "en" in the first dropdown, the same value should be not clickable in the second one (or the other way round)? Any Idea?

#!/usr/bin/perl use warnings; use strict; use Tk; use Tk::JComboBox; my $mw = MainWindow->new; my $lang1; my $lang2; my $drop1 = $mw->JComboBox( -textvariable => \$lang1, -choices => [qw(en fr de it sp)], -entrybackground => 'white', -background=> 'white', -disabledbackground=>'grey', -autofind => { -enable => 1 }, )->pack(); my $drop2 = $mw->JComboBox( -textvariable => \$lang2, -choices => [qw(en fr de it sp)], -entrybackground => 'white', -background=> 'white', -disabledbackground=>'grey', -autofind => { -enable => 1 }, )->pack(); MainLoop;

Replies are listed 'Best First'.
Re: Multiple Tk::JComboBox with unique values selectable
by Mr. Muskrat (Canon) on Jan 29, 2016 at 17:22 UTC

    If I'm reading the docs and examples correctly, I think you should be able to do something like this (untested):

    #!/usr/bin/perl use warnings; use strict; use Tk; use Tk::JComboBox; my $mw = MainWindow->new; my $lang1; my $lang2; my @choices = qw(en fr de it sp); my $drop1 = $mw->JComboBox( -textvariable => \$lang1, -choices => [@choices], -entrybackground => 'white', -background=> 'white', -disabledbackground=>'grey', -autofind => { -enable => 1 }, -selectcommand => \&changeDrop2 )->pack(); my $drop2 = $mw->JComboBox( -textvariable => \$lang2, -choices => [@choices], -entrybackground => 'white', -background=> 'white', -disabledbackground=>'grey', -autofind => { -enable => 1 }, )->pack(); MainLoop; sub changeDrop2 { my ($drop1, $selIndex, $selValue, $selName) = @_; my @restricted = grep { $_ ne $selValue } @choices; $drop2->configure(-choices => [@restricted]); $mw->update; }

      Thank you so much! It seems to work even if some behaviour is still to be improved, but a very GOOD starting point!