Tkinter Widget-MenuButton

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-
  1. from tkinter import *  
  2. import tkinter  
  3. main = Tk()  
  4. mb= Menubutton ( main, text="C# corner", relief=RAISED )  
  5. mb.grid()  
  6. mb.menu = Menu ( mb, tearoff = 0 )  
  7. mb["menu"] = mb.menu  
  8. mayoVar = IntVar()  
  9. ketchVar = IntVar()  
  10. mb.menu.add_checkbutton ( label="pyhon",  
  11. variable=mayoVar )  
  12. mb.menu.add_checkbutton ( label=".net",  
  13. variable=ketchVar )  
  14. mb.pack()  
  15. main.mainloop()  
Output-


Option
Description
activebackground
Sets the background color of the button when widgets is under the cursor.
activeforegroundSets 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.
padxIt 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.
underlineIt 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.