Skip to content
Related Articles

Related Articles

Python – MenuBars in wxPython
  • Last Updated : 10 May, 2020

One of the most important part in a GUI is a menubar, which are used to perform various operations on a Window. In this article we will learn how to create a menubar and add menu item to it. This can be achieved using MenuBar() constructor and Append() function in wx.MenuBar class.

Syntax for MenuBar() constructor:


Syntax for Append() function:

wx.MenuBar.Append(self, menu, title)


ParameterInput TypeDescription
menuwx.MenuThe menu to add. Do not deallocate this menu after calling Append .
titlestringThe title of the menu, must be non-empty.

Code Example:

# import wxPython 
import wx
class Example(wx.Frame):
    def __init__(self, *args, **kwargs):
        super(Example, self).__init__(*args, **kwargs)
    def InitUI(self):
        # create MenuBar using MenuBar() function
        menubar = wx.MenuBar()
        fileMenu = wx.Menu()
        # add menu to MenuBar
        menubar.Append(fileMenu, '&Menu# 1')
        self.SetSize((300, 200))
        self.SetTitle('Menu Bar')
def main():
    app = wx.App()
    ex = Example(None)
if __name__ == '__main__':

Output :

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up
Recommended Articles
Page :