Tuesday, June 9, 2026
HomeLanguageswxPython – check items inside Menu

wxPython – check items inside Menu

In this article we are going to learn about check menu item inside Menu in Menubars. We will write a code to show and hide statusbar using Check() function.

Parameters :

Parameter Input Type Description
id int The menu item identifier.
check bool If True, the item will be checked, otherwise it will be unchecked.

Code :




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()
        viewMenu = wx.Menu()
  
        self.showsb = viewMenu.Append(wx.ID_ANY, 'Show statusbar',
                                                 'Show Statusbar'
                                            kind = wx.ITEM_CHECK)
  
        viewMenu.Check(self.showsb.GetId(), True)
   
        self.Bind(wx.EVT_MENU, self.shStatusBar, self.showsb)
  
        menubar.Append(viewMenu, '&View')
        self.SetMenuBar(menubar)
  
        self.statusbar = self.CreateStatusBar()
        self.statusbar.SetStatusText('This is statusbar')
  
        self.SetSize((450, 350))
        self.SetTitle('Check menu item')
        self.Centre()
  
  
    def shStatusBar(self, e):
  
        if self.showsb.IsChecked():
            self.statusbar.Show()
        else:
            self.statusbar.Hide()
  
def main():
  
    app = wx.App()
    ex = Example(None)
    ex.Show()
    app.MainLoop()
  
  
if __name__ == '__main__':
    main()


Output :

checked :

unchecked :

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6896 POSTS0 COMMENTS
Nicole Veronica
12012 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7018 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6963 POSTS0 COMMENTS