wxPython menu

Most desktop applications have a window menu. They may look different depending the operating system.

wxPython will make every desktop application look like a native app. If you want the same appearance on every platform consider using another GUI framework.

wxPython menu bar
Menu in wxPython application

wxPython menu

The code below will create a menubar in your wxPython window:

import wx
app = wx.App()
frame = wx.Frame(None, -1, 'win.py')
# Setting up the menu.
filemenu= wx.Menu()
filemenu.Append(101, "Open", "Open")
filemenu.Append(102, "Save", "Save")
filemenu.Append(wx.ID_ABOUT, "About","About")
# Creating the menubar.
menuBar = wx.MenuBar()
menuBar.Append(filemenu,"File") # Adding the "filemenu" to the MenuBar
frame.SetMenuBar(menuBar)  # Adding the MenuBar to the Frame content.

A menu in wxPython is simple a wx.MenuBar().

This menu alone will not do anything, it needs to have several sub-menus such as a File menu. A sub-menu can be created with wx.Menu() which in turn has several items.

Finally, we set the frame’s menubar to the menubar we created.

wxPython has some default ids such as wx.ID_ABOUT and wx.ID_EXIT, which are both just integers. You can define your own ids as we did (101,  102).