Friday, June 12, 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
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6897 POSTS0 COMMENTS
Nicole Veronica
12013 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6963 POSTS0 COMMENTS