| 1 |
|
| 2 |
=head1 NAME |
| 3 |
|
| 4 |
Tk::Optionmenu - Let the user select one of some predefined options values |
| 5 |
|
| 6 |
=for pm Tk/Optionmenu.pm |
| 7 |
|
| 8 |
=for category Tk Widget Classes |
| 9 |
|
| 10 |
=head1 SYNOPSIS |
| 11 |
|
| 12 |
use Tk::Optionmenu; |
| 13 |
|
| 14 |
$opt = $w->Optionmenu( |
| 15 |
-options => REFERENCE_to_OPTIONLIST, |
| 16 |
-command => CALLBACK, |
| 17 |
-variable => SCALAR_REF, |
| 18 |
); |
| 19 |
|
| 20 |
$opt->addOptions( OPTIONLIST ); |
| 21 |
|
| 22 |
# OPTION LIST is |
| 23 |
# a) $val1, $val2, $val3,... |
| 24 |
# b) [ $lab1=>$val1], [$lab2=>val2], ... ] |
| 25 |
# c) combination of a) and b), e.g., |
| 26 |
# val1, [$lab2=>val2], val3, val4, [...], ... |
| 27 |
|
| 28 |
=head1 DESCRIPTION |
| 29 |
|
| 30 |
The B<Optionmenu> widget allows the user chose between a given set |
| 31 |
of options. |
| 32 |
|
| 33 |
If the user should be able to change the available option have a look |
| 34 |
at L<Tk::BrowseEntry>. |
| 35 |
|
| 36 |
=head1 OPTIONS |
| 37 |
|
| 38 |
=over 4 |
| 39 |
|
| 40 |
=item -options |
| 41 |
|
| 42 |
(Re)sets the list of options presented. |
| 43 |
|
| 44 |
=item -command |
| 45 |
|
| 46 |
Defines the L<callback|Tk::callbacks> that is invokes when a new option |
| 47 |
is selected. |
| 48 |
|
| 49 |
=item -variable |
| 50 |
|
| 51 |
Reference to a scalar that contains the current value of the |
| 52 |
selected option. |
| 53 |
|
| 54 |
=item -textvariable |
| 55 |
|
| 56 |
Reference to a scalar that contains the text label of the current value of the |
| 57 |
selected option. |
| 58 |
|
| 59 |
=back |
| 60 |
|
| 61 |
=head1 METHODS |
| 62 |
|
| 63 |
=over 4 |
| 64 |
|
| 65 |
=item addOptions |
| 66 |
|
| 67 |
Adds OPTION_LIST to the already available options. |
| 68 |
|
| 69 |
=back |
| 70 |
|
| 71 |
=head1 EXAMPLE |
| 72 |
|
| 73 |
use Tk; |
| 74 |
my $mw = MainWindow->new(); |
| 75 |
|
| 76 |
my ($var, $tvar); |
| 77 |
my $opt = $mw->Optionmenu( |
| 78 |
-options => [[jan=>1], [feb=>2], [mar=>3], [apr=>4]], |
| 79 |
-command => sub { print "got: ", shift, "\n" }, |
| 80 |
-variable => \$var, |
| 81 |
-textvariable => \$tvar |
| 82 |
)->pack; |
| 83 |
|
| 84 |
$opt->addOptions([may=>5],[jun=>6],[jul=>7],[aug=>8]); |
| 85 |
|
| 86 |
my $f = $mw->Frame(-relief=>'groove', -borderwidth => 2)->pack; |
| 87 |
$f->Label(-textvariable=>\$tvar)->pack(-side => 'left'); |
| 88 |
$f->Label(-text => " -> ")->pack(-side => 'left'); |
| 89 |
$f->Label(-textvariable=>\$var)->pack(-side => 'left'); |
| 90 |
|
| 91 |
$mw->Button(-text=>'Exit', -command=>sub{$mw->destroy})->pack; |
| 92 |
|
| 93 |
MainLoop; |
| 94 |
|
| 95 |
=head1 SEE ALSO |
| 96 |
|
| 97 |
L<Tk::Menubutton>, L<Tk::BrowseEntry> |
| 98 |
|
| 99 |
=cut |
| 100 |
|