當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


wxPython wx.StaticText GetForegroundColour()用法及代碼示例

在本文中,我們將學習GetForegroundColour()與wxPython的wx.StaticText類別關聯的函數。GetForegroundColour()函數返回用於StaticText的字體或前景的顏色。顏色的格式為(R,G,B,A)。不需要參數GetForegroundColour()函數。

用法:
wx.StaticText.GetForegroundColour(self)

參數:
GetForegroundColour()函數中不需要任何參數。

Return Type:
顏色

代碼示例:

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

輸出窗口:




相關用法


注:本文由純淨天空篩選整理自RahulSabharwal大神的英文原創作品 wxPython – GetForegroundColour() function in wx.StaticText。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。