Tuesday, June 16, 2026
HomeLanguageswxPython – Add image with menuitem in wx.MenuBar

wxPython – Add image with menuitem in wx.MenuBar

In this article we are going to learn that how can we add a bitmap image with the menuitem associated with the menu present in menubar object of wx.MenuBar class.

Steps :
1. Create a menubar object of wx.MenuBar class.
2. Create a menu object of wx.Menu class.
3. Create a MenuItem using wx.MenuItem class.
4. Use SetBitmap() function to add bitmap image with menu item.

Syntax of SetBitmap() method: wx.MenuItem.SetBitmap(self, bitmap, checked=True)

Parameters of SetBitmap() method:

Parameter Input Type Description
bmp wx.Bitmap Bitmap we need to use with menuitem.
checked bool If checkable set to True else False.
Code Example:




import wx
  
APP_EXIT = 1
  
  
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)
  
        menubar = wx.MenuBar()
        fileMenu = wx.Menu()
        qmi = wx.MenuItem(fileMenu, APP_EXIT, '&Quit\tCtrl + Q')
        qmi.SetBitmap(wx.Bitmap('right.png'))
        fileMenu.Append(qmi)
  
        self.Bind(wx.EVT_MENU, self.OnQuit, id = APP_EXIT)
  
        menubar.Append(fileMenu, '&File')
        self.SetMenuBar(menubar)
  
        self.SetSize((350, 250))
        self.SetTitle('Icons and shortcuts')
        self.Centre()
  
    def OnQuit(self, e):
        self.Close()
  
  
def main():
    app = wx.App()
    ex = Example(None)
    ex.Show()
    app.MainLoop()
  
  
if __name__ == '__main__':
    main()


Output:

Last Updated :
04 Jun, 2020
Like Article
Save Article

<!–

–>

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

Most Popular

Dominic
32516 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6897 POSTS0 COMMENTS
Nicole Veronica
12013 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6964 POSTS0 COMMENTS