📜  wxPython - 获取静态文本的默认属性

📅  最后修改于: 2022-05-13 01:55:07.479000             🧑  作者: Mango

wxPython - 获取静态文本的默认属性

在本文中,我们将学习如何获取 StaticText 的不同属性,例如背景、前景色和字体。我们使用 GetClassDefaultAttributes()函数来获取 wx.VisualAttributes 的对象。它可能会或可能不会将变体作为参数。

代码示例:

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


控制台输出:
(240, 240, 240, 255)
(0, 0, 0, 255)

输出窗口: