In this article we are going to learn about SetMenu() function associated with wx.MenuItem class of wxPython. SetMenu() function sets the parent menu which will contain this menu item. It takes a single wx.Menu object as parameter.
Syntax:
wx.MenuItem.SetMenu(self, menu)Parameters:
Parameter Input Type Description menu wx.Menu Parent menu for this item.
Code Example:
import wx class Example(wx.Frame): def __init__( self , * args, * * kwargs): super (Example, self ).__init__( * args, * * kwargs) self .InitUI() def InitUI( self ): self .locale = wx.Locale(wx.LANGUAGE_ENGLISH) self .menubar = wx.MenuBar() self .fileMenu = wx.Menu() self .st = wx.StaticText( self , label = "", pos = ( 20 , 20 ), style = wx.ALIGN_LEFT) self .item = wx.MenuItem( None , 1 , '&Radio' , kind = wx.ITEM_CHECK) # INITIAL MENU WAS NONE NOW INCLUDE MENUITEM TO self.fileMenu self .item.SetMenu( self .fileMenu) self .fileMenu.Append( self .item) self .menubar.Append( self .fileMenu, '&File' ) self .SetMenuBar( self .menubar) self .SetSize(( 350 , 250 )) self .SetTitle( 'Icons and shortcuts' ) self .Centre() def main(): app = wx.App() ex = Example( None ) ex.Show() app.MainLoop() if __name__ = = '__main__' : main() |
Output: