Menubuttion is used in dropdown menu and menu having more than one option to be selected by the user.
Syntax-
w = Menubutton ( main, option, ... )
Parameter-
Main- parent Window.
Option- attribute of button widget.
Example-
- from tkinter import *
- import tkinter
- main = Tk()
- mb= Menubutton ( main, text="C# corner", relief=RAISED )
- mb.grid()
- mb.menu = Menu ( mb, tearoff = 0 )
- mb["menu"] = mb.menu
- mayoVar = IntVar()
- ketchVar = IntVar()
- mb.menu.add_checkbutton ( label="pyhon",
- variable=mayoVar )
- mb.menu.add_checkbutton ( label=".net",
- variable=ketchVar )
- mb.pack()
- main.mainloop()
Output-

Option
| Description |
activebackground
| Sets the background color of the button when widgets is under the cursor.
|
activeforeground | Sets the foreground color of widgets , when widgets are under the cursor.
|
anchor
| It is used to set the position of the text.
|
bg
| Normal background color.
|
bitmap
| It is used to set bitmap name's.
|
bd
| It is used to set border width in pixels. Default is 2.
|
cursor
| Cursor is used to create a cursor in widgets like arrow, circle, dot etc.
|
direction
| It is used to set the direction of menu to be displayed.
|
disabledforeground
| It is used to disable foreground.
|
fg
| It sets normal foreground color of widgets.
|
height
| It is used to set the height of widgets.
|
highlightcolor | It changes the color of widgets on focus.
|
image
| It is used to set image on menu
|
justify
| It is Used to justify the text of menu.
|
menu
| It is used to add menu options.
|
padx | It is used to add additional padding left and right of text of widgets.
|
relief
| Relief is special type of border. The values are SUNKEN, RAISED, GROOVE, and RIDGE. |
text
| It is used to set the text on menu.
|
textvariable
| It is used to store the value.
|
underline | It is used to underline and default is -1, which means no underline text.
|
width
| It is used to set the width of widgets.
|
wraplength
| It is used to set the wrapping length.
|
Summary
In this Chapter, you learnt what menubutton widget is and how to use the property of the widget.