Commit | Line | Data |
---|---|---|
86530b38 AT |
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 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 | =back | |
55 | ||
56 | =head1 METHODS | |
57 | ||
58 | =over 4 | |
59 | ||
60 | =item addOptions | |
61 | ||
62 | Adds OPTION_LIST to the already available options. | |
63 | ||
64 | =back | |
65 | ||
66 | =head1 EXAMPLE | |
67 | ||
68 | use Tk; | |
69 | my $mw = MainWindow->new(); | |
70 | ||
71 | my $var; | |
72 | my $opt = $mw->Optionmenu( | |
73 | -options => [qw(jan feb mar apr)], | |
74 | -command => sub { print "got: ", shift, "\n" }, | |
75 | -variable => \$var, | |
76 | )->pack; | |
77 | ||
78 | $opt->addOptions([may=>5],[jun=>6],[jul=>7],[aug=>8]); | |
79 | ||
80 | $mw->Label(-textvariable=>\$var, -relief=>'groove')->pack; | |
81 | $mw->Button(-text=>'Exit', -command=>sub{$mw->destroy})->pack; | |
82 | ||
83 | MainLoop; | |
84 | ||
85 | =head1 SEE ALSO | |
86 | ||
87 | L<Tk::Menubutton>, L<Tk::BrowseEntry> | |
88 | ||
89 | =cut | |
90 |