Change the colour of a StaticText, wxPython

醉酒当歌 提交于 2019-12-01 13:51:05

问题


I need to make a StaticText red, what should I use?


回答1:


Here it is

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:


Depending on which color you would need to set, look into SetForegroundColour() or SetBackgroundColour() method.




回答3:


This should work:

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

If you are using it inside the panel or frame's class then:

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

wx.Colour takes RGB values which can be used for different colours.



来源:https://stackoverflow.com/questions/1785227/change-the-colour-of-a-statictext-wxpython

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!