wxPython wx.StaticText中的GetForegroundColour()函数

wxPython wx.StaticText中的GetForegroundColour()函数

在这篇文章中,我们将学习与wxPython的wx.StaticText类有关的GetForegroundColour()函数。GetForegroundColour()函数返回用于StaticText的字体或前景的颜色。颜色的格式为(R, G, B, A)。GetForegroundColour()函数不需要参数。

语法: wx.StaticText.GetForegroundColour(self)

参数: GetForegroundColour()函数不需要参数。

返回类型: wx.Colour

代码示例

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

控制台输出

(10, 20, 255, 255)

输出窗口:

wxPython wx.StaticText中的GetForegroundColour()函数

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

wxPython 教程