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:
wx.MenuBar(style=0)
Syntax for Append() function:
wx.MenuBar.Append(self, menu, title)
Parameters:
Parameter |
Input Type |
Description |
menu |
wx.Menu |
The menu to add. Do not deallocate this menu after calling Append . |
title |
string |
The title of the menu, must be non-empty. |
Code Example:
import wx
class Example(wx.Frame):
def __init__( self , * args, * * kwargs):
super (Example, self ).__init__( * args, * * kwargs)
self .InitUI()
def InitUI( self ):
menubar = wx.MenuBar()
fileMenu = wx.Menu()
menubar.Append(fileMenu, '&Menu# 1' )
self .SetMenuBar(menubar)
self .SetSize(( 300 , 200 ))
self .SetTitle( 'Menu Bar' )
def main():
app = wx.App()
ex = Example( None )
ex.Show()
app.MainLoop()
if __name__ = = '__main__' :
main()
|
Output :
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...