Thursday, September 4, 2025
HomeLanguageswxPython – GetBackgroundColour() function in wx.MenuBar

wxPython – GetBackgroundColour() function in wx.MenuBar

In this article we are going to learn about GetBackgroundColour() function associated with the wx.MenuBar class of wxPython. As the name suggests GetBackgroundColour() returns the background colour associated with the menu item. GetBackgroundColour() function takes no parameters.

Syntax: wx.MenuBar.GetBackgroundColour(self)

Parameters: No parameters are required in GetBackgroundColour() function

Return Type: wx.Colour

Code Example 1:




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, '&Check')
        self.fileMenu.Append(self.item)
  
        # print the background colour of menu item
        print(self.item.GetBackgroundColour())
        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:

(-1, -1, -1, 255)

Code Example 2:




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, '&Check')
        self.item.SetBackgroundColour((225, 200, 100, 255))
        self.fileMenu.Append(self.item)
  
        # print the background colour of menu item
        print(self.item.GetBackgroundColour())
        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:

(225, 200, 100, 255)
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
32264 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6632 POSTS0 COMMENTS
Nicole Veronica
11800 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11860 POSTS0 COMMENTS
Shaida Kate Naidoo
6749 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6698 POSTS0 COMMENTS
Umr Jansen
6718 POSTS0 COMMENTS