Friday, January 30, 2026
HomeLanguageswxPython – GetForegroundColour() function in wx.StaticText

wxPython – GetForegroundColour() function in wx.StaticText

In this article we are going to learn about GetForegroundColour() function associated with wx.StaticText class 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: 

Python3




# 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()


Console Output:

(10, 20, 255, 255)

Output Window:

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

Most Popular

Dominic
32478 POSTS0 COMMENTS
Milvus
122 POSTS0 COMMENTS
Nango Kala
6849 POSTS0 COMMENTS
Nicole Veronica
11978 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12065 POSTS0 COMMENTS
Shaida Kate Naidoo
6987 POSTS0 COMMENTS
Ted Musemwa
7222 POSTS0 COMMENTS
Thapelo Manthata
6934 POSTS0 COMMENTS
Umr Jansen
6917 POSTS0 COMMENTS