Skip to content
Related Articles

Related Articles

wxPython – GetForegroundColour() function in wx.StaticText

View Discussion
Improve Article
Save Article
  • Last Updated : 01 Aug, 2020
View Discussion
Improve Article
Save Article

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:




# 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:


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!