|
|
|
|
|
-background, -bitmap, -command, -font, -foreground, -image, -indicatoron, -label, -menu, -offvalue, -onvalue, -selectcolor, -selectimage, -state, -underline, -value, and -variable. |
|
|
|
|
|
|
|
|
The results of the following two code snippets are identical: |
|
|
|
 |
|
|
|
|
# Snippet 1
# Using add for menu items
$menu = $mw->Menu;
$menu->add("command", -label => "Open",
-command => \&open_file);
$menu->add("command", -label => "Close",
-command => \&close_file);
#Snippet 2
# Sending a list intially using -menuitems option
$menu = $mw->Menu(-menuitems => [ ["command" => "Open",
-command => \&open_file],
["command" => "Close",
-command => \&close_file]
]); |
|
|
|
|
|
|
|
|
Each additional call to add will add another item to the end of the menu. To add a menu item to somewhere other than the end of the menu, see the insert method (covered in the next section). |
|
|
|
|
|
|
|
|
Instead of -text or -textvariable options, we use -label to indicate the text shown on the menu item. You should notice that we don't have a -labelvariable option. If you need to change the text shown in the menu item, you will need to use the entryconfigure method (discussed later in this chapter). |
|
|
|
|
|
|
|
|
The insert method works exactly the same way the add method works, except the new menu item will be inserted right before the menu item at index. You cannot insert a menu item before the tear-off menu item because the tear-off must always be the first item in the menu: |
|
|
|
 |
|
|
|
|
$menu->insert(index, type [, options ... ]); |
|
|
|
 |
|
|
|
|
$menu->insert("end", "radiobutton", -label=>"red"); |
|
|
|
|
|
|
|
|
To remove menu items from your menu, use the delete method: |
|
|
|
 |
|
|
|
|
$menu->delete(index);
# or..
$menu->delete(index1, index2); |
|
|
|
|