wxPython – GetForegroundColour() function in wx.StaticText

In this article we are going to learn about GetForegroundColour() function associated with wx.StaticText clas of wxPython. GetForegroundColour() function returns the colour that is used for font or foreground of StaticText. Colour is in format of (R, G, B, A). No parameters are required in GetForegroundColour() function.

Syntax:
wx.StaticText.GetForegroundColour(self)

Parameters:
No parameters are required in GetForegroundColour() function.

Return Type:
wx.Colour

Code Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing the module
import wx
     
# definition of the Example class
class Example(wx.Frame):
     
    # instantiating the class
    def __init__(self, *args, **kwargs):
        super(Example, self).__init__(*args, **kwargs)
    
        self.InitUI()
    
    # method for creation of user interface
    def InitUI(self):
        self.locale = wx.Locale(wx.LANGUAGE_ENGLISH)
  
        # create parent panel for button
        self.pnl = wx.Panel(self)
  
        # create button at point (20, 20)
        self.st = wx.StaticText(self.pnl, id = 1, label ="Button")
          
        # change foreground colour of button
        self.st.SetForegroundColour((10, 20, 255, 255))
         
        # get foreground colour
        fc = self.st.GetForegroundColour()
  
        # print foreground colour
        print(fc)
  
        self.SetSize((350, 250))
        self.SetTitle('wx.Button')
        self.Centre()
  
# definition of the main function
def main():
     
    # creating an App object
    app = wx.App()
     
    # creating an Example object
    ex = Example(None)
     
    # showing the Example object
    ex.Show()
     
    # running the App object
    app.MainLoop()
      
# driver code
if __name__ == '__main__':
    main()

chevron_right


Console Output:

(10, 20, 255, 255)

Output Window:




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.