1Menu::Item(3) User Contributed Perl Documentation Menu::Item(3)
2
3
4
6 Tk::Menu::Item - Base class for Menu items
7
9 require Tk::Menu::Item;
10
11 my $but = $menu->Button(...);
12 $but->configure(...);
13 my $what = $but->cget();
14
15 package Whatever;
16 require Tk::Menu::Item;
17 @ISA = qw(Tk::Menu::Item);
18
19 sub PreInit
20 {
21 my ($class,$menu,$info) = @_;
22 $info->{'-xxxxx'} = ...
23 my $y = delete $info->{'-yyyy'};
24 }
25
27 Tk::Menu::Item is the base class from which Tk::Menu::Button,
28 Tk::Menu::Cascade, Tk::Menu::Radiobutton and Tk::Menu::Checkbutton are
29 derived. There is also a Tk::Menu::Separator.
30
31 Constructors are declared so that $menu->Button(...) etc. do what you
32 would expect.
33
34 The "-label" option is pre-processed allowing ~ to be prefixed to the
35 character to derive a "-underline" value. Thus
36
37 $menu->Button(-label => 'Goto ~Home',...)
38
39 is equivalent to
40
41 $menu->Button(-label => 'Goto Home', -underline => 6, ...)
42
43 The "Cascade" menu item creates a sub-menu and accepts these options:
44
45 -menuitems
46 A list of items for the sub-menu. Within this list (which is also
47 accepted by Menu and Menubutton) the first two elements of each
48 item should be the "constructor" name and the label:
49
50 -menuitems => [
51 [Button => '~Quit', -command => [destroy => $mw]],
52 [Checkbutton => '~Oil', -variable => \$oil],
53 ]
54
55 -postcommand
56 A callback to be invoked before posting the menu.
57
58 -tearoff
59 Specifies whether sub-menu can be torn-off or not.
60
61 -menuvar
62 Scalar reference that will be set to the newly-created sub-menu.
63
64 The returned object is currently a blessed reference to an array of two
65 items: the containing Menu and the 'label'. Methods "configure" and
66 "cget" are mapped onto underlying "entryconfigure" and "entrycget".
67
68 The main purpose of the OO interface is to allow derived item classes
69 to be defined which pre-set the options used to create a more basic
70 item.
71
73 This OO interface is very new. Using the label as the "key" is a
74 problem for separaror items which don't have one. The alternative would
75 be to use an index into the menu but that is a problem if items are
76 deleted (or inserted other than at the end).
77
78 There should probably be a PostInit entry point too, or a more widget
79 like defered 'configure'.
80
81
82
83perl v5.30.1 2020-01-30 Menu::Item(3)