The Wayback Machine - https://web.archive.org/web/20230512155138/https://www.geeksforgeeks.org/wxpython-get-default-attributes-of-statictext/
Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

wxPython – Get Default Attributes of StaticText

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

In this article, we are going to learn how can we get different attributes of StaticText like background, foreground colors, and fonts. We use GetClassDefaultAttributes() function to get an object of wx.VisualAttributes. It may or may not take variant as an argument.

Syntax: 
wx.StaticText.GetClassDefaultAttributes() 
or 
wx.StaticText.GetClassDefaultAttributes(variant=WINDOW_VARIANT_NORMAL)

Parameters: 

ParameterInput TypeDescription
variantWindowVariantvariant for static text.

Return Type: 
wx.VisualAttributes
 

Code Example:  

Python3




import wx
 
 
class Example(wx.Frame):
 
    def __init__(self, *args, **kwargs):
        super(Example, self).__init__(*args, **kwargs)
        self.InitUI()
 
    def InitUI(self):
        self.locale = wx.Locale(wx.LANGUAGE_ENGLISH)
        self.pnl = wx.Panel(self)
 
        bmp = wx.Bitmap('right.png')
        # CREATE STATICTEXT AT POINT (20, 20)
        self.st = wx.StaticText(self.pnl, id = 1, label ="This is the Label.", pos =(20, 20),
                                size = wx.DefaultSize, style = wx.ST_ELLIPSIZE_MIDDLE, name ="statictext")
 
        self.st.SetBackgroundColour((255, 252, 92, 255))
        self.st.SetForegroundColour((14, 96, 150, 255))
         
        # GET DEFAULT ATTRIBUTES OBJECT
        v = self.st.GetClassDefaultAttributes();
        print(v.colBg)
        print(v.colFg)
        print(v.font)
 
        self.SetSize((350, 250))
        self.SetTitle('wx.Button')
        self.Centre()
 
def main():
    app = wx.App()
    ex = Example(None)
    ex.Show()
    app.MainLoop()
 
 
if __name__ == '__main__':
    main()

Console Output: 
(240, 240, 240, 255) 
(0, 0, 0, 255)

Output Window: 

 


My Personal Notes arrow_drop_up
Last Updated : 21 Sep, 2021
Like Article
Save Article
Similar Reads
Related Tutorials