更改StaticText的颜色,wxPython

时间:2009-11-23 18:57:45

标签: wxpython static-text

我需要将StaticText设为红色,我应该使用什么?

3 个答案:

答案 0 :(得分:26)

这是

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

答案 1 :(得分:2)

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

答案 2 :(得分:1)

这应该有效:

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

如果您在面板或框架类中使用它,那么:

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

wx.Colour获取可用于不同颜色的RGB值。

相关问题