Friday, October 3, 2025
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
32331 POSTS0 COMMENTS
Milvus
85 POSTS0 COMMENTS
Nango Kala
6703 POSTS0 COMMENTS
Nicole Veronica
11868 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11929 POSTS0 COMMENTS
Shaida Kate Naidoo
6818 POSTS0 COMMENTS
Ted Musemwa
7080 POSTS0 COMMENTS
Thapelo Manthata
6775 POSTS0 COMMENTS
Umr Jansen
6776 POSTS0 COMMENTS