Let "-browsecmd" invoke a subroutine that takes care of the second choice and checks each element in the array against the element referenced in the captured variable. This subroutine is placed outside the MainLoop for better efficiency..01-Capture the user choice in a variable. 02-Check if it is in the populated array.
You need "-variable=>" from the BrowseEntry set of options to capture the user choice..
use strict; use warnings; use Tk; require Tk::BrowseEntry; my @items = qw(first second third fourth); my $mw = MainWindow->new(); my $default_choice = "first"; my $dropDown = $mw->BrowseEntry( -label=>'items', -variable=>\$default_choice, #capture the user choice or show de +fault -browsecmd=>\&doIt )->pack(); $dropDown->insert('end', "First"); $dropDown->insert('end',"Second"); $dropDown->insert('end',"Third"); $mw->Button(-text=>'exit', -command=>sub{exit;})->pack(); MainLoop; #check if the array has an element identical to what's been chosen.. sub doIt{ my $x = -1; foreach my $element (@items){ $x++; print $element eq lc($default_choice)? "$default_choice index +\$items[$x]\n" : next; } }
In reply to Re: How can I get the index of the currently selected Tk::BrowseEntry element?
by biohisham
in thread How can I get the index of the currently selected Tk::BrowseEntry element?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |