In this wxPython article we want to learn about How to Create MenuBar in wxPython, menu bar is an essential element of any graphical user interface (GUI). because it allows users to access different features and functions of an application in an organized and easy way. in this article we want to talk that how to create a menu bar in wxPython, so wxPython is powerful and cross platform GUI library for Python.
This is the complete code for this article
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
import wx class MenuFrame(wx.Frame): def __init__(self, parent): wx.Frame.__init__(self, parent, title="GeeksCoders - Menu Example") self.menu_bar = wx.MenuBar() file_menu = wx.Menu() new_item = wx.MenuItem(file_menu, wx.ID_NEW, "&New\tCtrl+N", "Create a new file") file_menu.Append(new_item) self.menu_bar.Append(file_menu, "&File") self.SetMenuBar(self.menu_bar) if __name__ == '__main__': app = wx.App() frame = MenuFrame(None) frame.Show(True) app.MainLoop() |
In the above code first we have imported wxPython module.
1 |
import wx |
After that we need to create a menu bar using wx.MenuBar class. menu bar constructor takes no arguments.
1 |
menu_bar = wx.MenuBar() |
The next step is to create one or more menus using wx.Menu class. each menu is added to the menu bar using the Append method.
1 2 |
file_menu = wx.Menu() menu_bar.Append(file_menu, "&File") |
The final step is to add items to the menus using wx.MenuItem class. each menu item is added to a menu using the Append method, in this code we are creating a New menu item with ID wx.ID_NEW and the label New. we are also assigning a keyboard shortcut using \t character and adding a tooltip with the text Create a new file. menu item is added to the File menu.
1 2 |
new_item = wx.MenuItem(file_menu, wx.ID_NEW, "&New\tCtrl+N", "Create a new file") file_menu.Append(new_item) |
Run the complete code and this will be the result

Learn More on wxPython
- How to Create wxPython Main Window wx.Frame
- How to Create wxPython Panel with wx.Panel
- How to Create wxPython Button
- How to Create wxPython Text Control
- How to Create wxPython Static Text
- How to Create wxPython CheckBox
- How to Create wxPython RadioButton
- How to Create List Box in wxPython
- How to Create ComboBox in wxPython
- How to Create Slider in wxPython