Thursday, August 28, 2025
HomeLanguageswxPython – Change Font colour of Radio Button

wxPython – Change Font colour of Radio Button

In this article we are going to learn that how can we change the foreground or font color of the radio button. In order to change the foreground colour of Radio Button we will use SetForegroundColour() function. SetForegroundColour() function sets the foreground colour of the window.

The meaning of foreground colour varies according to the window class; it may be the text colour or other colour, or it may not be used at all. Additionally, not all native controls support changing their foreground colour so this method may change their colour only partially or even not at all.

Syntax: wx.RadioButton.SetForegroundColour(self, colour)

Parameters:

Parameter Input Type Description
colour wx.Colour colour for the background.

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

Return Type: bool

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):
          
        # create parent panel in the frame
        self.pnl = wx.Panel(self)
  
        # create radio button at position (30, 10)
        self.rb1 = wx.RadioButton(self.pnl, label ='Btn1'
                            pos =(30, 10), size =(100, 20))
  
  
        # change background colour
        self.rb1.SetBackgroundColour((233, 227, 100, 255))
  
        # change foreground colour
        self.rb1.SetForegroundColour((0, 0, 255, 255))
  
  
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
32244 POSTS0 COMMENTS
Milvus
80 POSTS0 COMMENTS
Nango Kala
6615 POSTS0 COMMENTS
Nicole Veronica
11787 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11832 POSTS0 COMMENTS
Shaida Kate Naidoo
6728 POSTS0 COMMENTS
Ted Musemwa
7009 POSTS0 COMMENTS
Thapelo Manthata
6684 POSTS0 COMMENTS
Umr Jansen
6697 POSTS0 COMMENTS