2009-11-23 75 views

回答

20

import wx 

app=wx.PySimpleApp() 
frame=wx.Frame(None) 
text=wx.StaticText(frame, label="Colored text") 
text.SetForegroundColour((255,0,0)) # set text color 
text.SetBackgroundColour((0,0,255)) # set text back color 
frame.Show(True) 
app.MainLoop() 
2

根据您需要设置的颜色,查看SetForegroundColour()SetBackgroundColour()方法。

1

这应该工作:

text.SetForegroundColour(wx.Colour(255,255,255)) 

如果您使用的是它的面板或框架的类中,则:

self.text.SetForegroundColour(wx.Colour(255,255,255)) 

wx.Colour采用RGB值,其可以用于不同的颜色。

0

随着wxPython的菲尼克斯(我不知道古典wxPython的),你可以使用:

static_text = wx.StaticText(parent) 
static_text.SetLabelMarkup("<span foreground='red'>Some text</span>") 

有关SetLabelMarkup功能的详细信息,请参阅the Control class documentation