所以我正在从头开始编写代码,我只需要放置一个灰色背景的静态文本(不变)。我可以用.ForegroundColour
但不能用BackgroundColour
这是代码
s_text2 = wx.StaticText(self.panel1, -1, "\n\n\nStop\n\n\n", (x1size+30,10))
s_text2.SetBackgroundColour('grey')
有什么想法吗?
是的,这是一个简短的示例
import wx
class Prototype(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, None, size=(550,300))
self.InitUI()
self.Centre()
self.Show()
#define User Interface
def InitUI(self):
self.panel1 = wx.Panel(self, -1)
self.sizer = wx.BoxSizer() #Main window sizer
self.sizer.Add(self.panel1, 1, flag=wx.EXPAND)
self.hbox = wx.BoxSizer(wx.HORIZONTAL)
self.panel1.SetSizer(self.hbox)
#Static Text
s_text1 = wx.StaticText(self.panel1, -1, "Hello World!", (10,5)) #top text
self.s_text2 = wx.StaticText(self.panel1, -1, "\n\n\nStop\n\n\n", (300,10)) #top text
self.s_text2.SetBackgroundColour("blue")
if __name__ == '__main__':
app = wx.App()
Prototype(None, title='')
app.MainLoop()
`