Thursday, January 22, 2026
HomeLanguageswxPython – change toolbar colour wx.ToolBar

wxPython – change toolbar colour wx.ToolBar

In this article we are going to learn to change the colour of toolbar. We will simply use SetBackgroundColour() function in order to do this. SetBackgroundColour() simply sets the background colour of the window. It takes a wx.Colour parameter, i.e., the colour to be used as the background colour.

Syntax: wx.ToolBar.SetBackgroundColour(self, colour) Parameters:

Parameter Input Type Description
colour wx.Colour The colour to be used as the background colour

Return Type: bool Returns: True if the colour was really changed, False if it was already set to this colour and nothing was done.

Code Example: 

Python3




import wx
 
 
class Example(wx.Frame):
    global count
    count = 0;
 
    def __init__(self, *args, **kwargs):
        super(Example, self).__init__(*args, **kwargs)
 
        self.InitUI()
 
    def InitUI(self):
        self.locale = wx.Locale(wx.LANGUAGE_ENGLISH)
        pnl = wx.Panel(self)
        self.toolbar = self.CreateToolBar()
 
        # Add tools to toolbar
        ptool = self.toolbar.AddTool(12, 'oneTool',
                                     wx.Bitmap('right.png'),
                                     wx.Bitmap('wrong.png'), shortHelp ="Simple Tool")
 
        qtool = self.toolbar.AddTool(12, 'oneTool', wx.Bitmap('wrong.png'),
                                     wx.Bitmap('wrong.png'), shortHelp ="Simple Tool")
 
        # change background colour of toolbar
        self.toolbar.SetBackgroundColour((255, 200, 50, 255))
 
        self.toolbar.Realize()
        self.SetSize((350, 250))
        self.SetTitle('Control')
        self.Centre()
 
 
def main():
    app = wx.App()
    ex = Example(None)
    ex.Show()
    app.MainLoop()
 
 
if __name__ == '__main__':
    main()


Output Window:

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

Most Popular

Dominic
32475 POSTS0 COMMENTS
Milvus
119 POSTS0 COMMENTS
Nango Kala
6847 POSTS0 COMMENTS
Nicole Veronica
11977 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12064 POSTS0 COMMENTS
Shaida Kate Naidoo
6986 POSTS0 COMMENTS
Ted Musemwa
7220 POSTS0 COMMENTS
Thapelo Manthata
6933 POSTS0 COMMENTS
Umr Jansen
6912 POSTS0 COMMENTS