English 中文(简体)
Change the colour of a StaticText, wxPython
原标题:

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

最佳回答

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()
问题回答

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

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.





相关问题
Getting value of TextCtrl from a different wxPanel

I was trying to get my first wxWindow application to work and I ran into following difficulty: I create wxPanel and add a wxNotebook object to it. Then I add a page to notebook created from another ...

Displaying OpenCV iplimage data structures with wxPython

Here is my current code (language is Python): newFrameImage = cv.QueryFrame(webcam) newFrameImageFile = cv.SaveImage("temp.jpg",newFrameImage) wxImage = wx.Image("temp.jpg", wx.BITMAP_TYPE_ANY)....

Tree view GUI widget/gui library that can do multiple icons?

Screenshot I m looking to recreate this in Python; I can t find a library that seems to have what I need. Are there any GUI libraries that might possibly have this? - I have scoured wxWidgets (which ...

Alternatives to wx.lib.masked.NumCtrl

In a wxPython application I m developing I need a lot of input fields for numbers (integers and floats), so I tried using wx.lib.masked.NumCtrl, but my users now tell me that it s quite uncomfortable ...

热门标签