1Optionmenu(3) User Contributed Perl Documentation Optionmenu(3)
2
3
4
6 Tk::Optionmenu - Let the user select one of some predefined options
7 values
8
10 use Tk::Optionmenu;
11
12 $opt = $w->Optionmenu(
13 -options => REFERENCE_to_OPTIONLIST,
14 -command => CALLBACK,
15 -variable => SCALAR_REF,
16 );
17
18 $opt->addOptions( OPTIONLIST );
19
20 # OPTION LIST is
21 # a) $val1, $val2, $val3,...
22 # b) [ $lab1=>$val1], [$lab2=>val2], ... ]
23 # c) combination of a) and b), e.g.,
24 # val1, [$lab2=>val2], val3, val4, [...], ...
25
27 The Optionmenu widget allows the user chose between a given set of
28 options.
29
30 If the user should be able to change the available option have a look
31 at Tk::BrowseEntry.
32
34 -options
35 (Re)sets the list of options presented.
36
37 -command
38 Defines the callback that is invokes when a new option is selected.
39
40 -variable
41 Reference to a scalar that contains the current value of the
42 selected option.
43
44 -textvariable
45 Reference to a scalar that contains the text label of the current
46 value of the selected option.
47
49 addOptions
50 Adds OPTION_LIST to the already available options.
51
53 use Tk;
54 my $mw = MainWindow->new();
55
56 my ($var, $tvar);
57 my $opt = $mw->Optionmenu(
58 -options => [[jan=>1], [feb=>2], [mar=>3], [apr=>4]],
59 -command => sub { print "got: ", shift, "\n" },
60 -variable => \$var,
61 -textvariable => \$tvar
62 )->pack;
63
64 $opt->addOptions([may=>5],[jun=>6],[jul=>7],[aug=>8]);
65
66 my $f = $mw->Frame(-relief=>'groove', -borderwidth => 2)->pack;
67 $f->Label(-textvariable=>\$tvar)->pack(-side => 'left');
68 $f->Label(-text => " -> ")->pack(-side => 'left');
69 $f->Label(-textvariable=>\$var)->pack(-side => 'left');
70
71 $mw->Button(-text=>'Exit', -command=>sub{$mw->destroy})->pack;
72
73 MainLoop;
74
76 Tk::Menubutton, Tk::BrowseEntry
77
78
79
80perl v5.8.8 2008-02-05 Optionmenu(3)