Next / Previous / Contents

15.1. Menu item creation (coption) options

Wherever the menu methods described above allow a coption, you may apply a value to any of the option names below by using the option name as a keyword argument with the desired value. For example, to make a command's text appear with red letters, use “foreground='red'” as an option to the add_command method call.

Table 24. Menu item coption values

accelerator To display an “accelerator” keystroke combination on the right side of a menu choice, use the option “accelerator=s” where s is a string containing the characters to be displayed. For example, to indicate that a command has Control-X as its accelerator, use the option “accelerator='^X'”. Note that this option does not actually implement the accelerator; use a keystroke binding to do that.
activebackground The background color used for choices when they are under the mouse.
activeforeground The foreground color used for choices when they are under the mouse.
background The background color used for choices when they are not under the mouse. Note that this cannot be abbreviated as bg.
bitmap Display a bitmap for this choice; see Section 5.7, “Bitmaps”.
columnbreak Normally all the choices are displayed in one long column. If you set columnbreak=1, this choice will start a new column to the right of the one containing the previous choice.
columnbreak Use option “columnbreak=True” to start a new column of choices with this choice.
command A procedure to be called when this choice is activated.
compound If you want to display both text and a graphic (either a bitmap or an image) on a menu choice, use this coption to specify the location of the graphic relative to the text. Values may be any of tk.LEFT, tk.RIGHT, tk.TOP, tk.BOTTOM, tk.CENTER, or tk.NONE. For example, a value of “compound=tk.TOP” would position the graphic above the text.
font The font used to render the label text. See Section 5.4, “Type fonts”
foreground The foreground color used for choices when they are not under the mouse. Note that this cannot be abbreviated as fg.
hidemargin By default, a small margin separates adjacent choices in a menu. Use the coptionhidemargin=True” to suppress this margin. For example, if your choices are color swatches on a palette, this option will make the swatches touch without any other intervening color.
image Display an image for this choice; see Section 5.9, “Images”.
label The text string to appear for this choice.
menu This option is used only for cascade choices. Set it to a Menu object that displays the next level of choices.
offvalue Normally, the control variable for a checkbutton is set to 0 when the checkbutton is off. You can change the off value by setting this option to the desired value. See Section 52, “Control variables: the values behind the widgets”.
onvalue Normally, the control variable for a checkbutton is set to 1 when the checkbutton is on. You can change the on value by setting this option to the desired value.
selectcolor Normally, the color displayed in a set checkbutton or radiobutton is red. Change that color by setting this option to the color you want; see Section 5.3, “Colors”.
selectimage If you are using the image option to display a graphic instead of text on a menu radiobutton or checkbutton, if you use selectimage=I, image I will be displayed when the item is selected.
state Normally, all choices react to mouse clicks, but you can set state=tk.DISABLED to gray it out and make it unresponsive. This coption will be tk.ACTIVE when the mouse is over the choice.
underline Normally none of the letters in the label are underlined. Set this option to the index of a letter to underline that letter.
value Specifies the value of the associated control variable (see Section 52, “Control variables: the values behind the widgets”) for a radiobutton. This can be an integer if the control variable is an IntVar, or a string if the control variable is a StringVar.
variable For checkbuttons or radiobuttons, this option should be set to the control variable associated with the checkbutton or group of radiobuttons. See Section 52, “Control variables: the values behind the widgets”.