Skip to content
Related Articles

Related Articles

wxPython – Change Background Colour of Radio Button

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 23 Aug, 2021

In this article we are going to learn about how can we change background colour of a Radio Button. We will use SetBackgroundColour() function sets the background colour of the window. 
Notice that as with SetForegroundColour, setting the background colour of a native control may not affect the entire control and could be not supported at all depending on the control and platform.
 

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

 

ParameterInput TypeDescription
colourwx.ColourColour for background of static text.

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
 
APP_EXIT = 1
 
 
class Example(wx.Frame):
 
    def __init__(self, *args, **kwargs):
        super(Example, self).__init__(*args, **kwargs)
 
        self.InitUI()
 
    def InitUI(self):
 
        # create parent panel for radio buttons
        self.pnl = wx.Panel(self)
 
        # create radio button in frame
        self.rb1 = wx.RadioButton(self.pnl, label ='Btn1',
                           pos =(30, 10), size =(100, 20))
 
        # set background colour to yellow (r, g, b, a)
        self.rb1.SetBackgroundColour((233, 227, 100, 255))
 
 
 
def main():
    app = wx.App()
    ex = Example(None)
    ex.Show()
    app.MainLoop()
 
 
if __name__ == '__main__':
    main()

Output Window: 
 

 


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!