Friday, November 14, 2025
HomeLanguageswxPython – SetBitmaps() function in wx.MenuItem

wxPython – SetBitmaps() function in wx.MenuItem

In this article we are going to learn about SetBitmaps() function associated with the wx.MenuItem class of wxPython. SetBitmaps() function Sets the checked/unchecked bitmaps for the menu item. The first bitmap is also used as the single bitmap for uncheckable menu items.
It takes two bitmaps as parameter for checked and unchecked status of menu item.

Syntax:

wx.MenuItem.SetBitmaps(self, checked, unchecked=NullBitmap)

Parameters:

Parameter Input Type Description
checked wx.Bitmap Bitmap to set for menu item while check.
unchecked wx.Bitmap Bitmap to set for menu item while uncheck.

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.item = wx.MenuItem(self.fileMenu, 1, '&Radio', helpString ="Check Help", kind = wx.ITEM_CHECK)
        # set bitmap for tool for checked and unchecked status
        self.item.SetBitmaps(checked = wx.Bitmap('right.png'), unchecked = wx.Bitmap('wrong.png'))
        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:
Checked :

Unchecked :

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

Most Popular

Dominic
32399 POSTS0 COMMENTS
Milvus
95 POSTS0 COMMENTS
Nango Kala
6765 POSTS0 COMMENTS
Nicole Veronica
11917 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11984 POSTS0 COMMENTS
Shaida Kate Naidoo
6889 POSTS0 COMMENTS
Ted Musemwa
7141 POSTS0 COMMENTS
Thapelo Manthata
6837 POSTS0 COMMENTS
Umr Jansen
6839 POSTS0 COMMENTS