In this tutorial, we will learn about Python Tkinter MenuButton. Tkinter MenuButton is a widget which we use to show the drop-down menu on the screen. We use a Menu widget with this MenuButton to show options to the user to select from.

Syntax to add Python Tkinter MenuButton

w = Menubutton (master, options)  
  • master: This represents the parent window.
  • options: Here is the list of most commonly used options for this widget.

Example Program of Python Tkinter MenuButton

from tkinter import *  
 
mainWindow = Tk()  

mainWindow.geometry("300x150")

menuButton=  Menubutton (mainWindow, text="Select Language", relief=RAISED )
menuButton.grid()
menuButton.menu =  Menu ( menuButton, tearoff = 0 )
menuButton["menu"] =  menuButton.menu

pythonVar = IntVar()
javaVar = IntVar()

menuButton.menu.add_checkbutton ( label="Python",
                          variable=pythonVar )
menuButton.menu.add_checkbutton ( label="Java",
                          variable=javaVar )

menuButton.pack()

mainWindow.mainloop() 

Output:

Python Tkinter MenuButton

Various possible options in Python Tkinter MenuButton:

OptionDescription
activebackgroundThis option is used to set background color of widget under focus.
activeforegroundThis option is used to set foreground color of widget under focus.
anchorThis option helps us to set position of text inside the widget. By default value of anchor is CENTER.
bgThis option helps us to set normal background color of widget.
bdThis option helps us to set the border size around widget.
cursorThis option helps us to set the style of cursor like an arrow, dot etc.
directionThis option is used to set the position of menu to display such as LEFT, RIGHT, or ABOVE. 
disabledforegroundThis option is used to disable text color of widget.
fgThis option helps us to set normal foreground colour of widget.
heightThis option helps us to set height of widget.
highlightcolorThis option is used to set highlight color shown to the widget under focus.
justifyThis helps us to automatically organize the text in multiple lines.
menuThis option is used to set menu with MenuButton.
padxThis option helps us to set space left and right of widget.
padyThis option helps us to set space above and below of widget.
reliefThis helps us to set the style of the border by which is default Flat.
stateThis option is used to set state of MenuButton such as ENABLE or DISABLE.
textThis option helps us to set string source for label.
underlineThis option helps us to underline specified letter of the text.
widthThis helps us to set the width of the widget in characters. By default it is 20.