Open In App

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)

Article Tags :