wxPython gridbagsizer 颜色 [英] wxPython gridbagsizer colour
问题描述
我正在测试一个应用程序.现在我想在中间面板周围有一个漂亮的边框,所以它被嵌入到另一个面板中.但是,当我想在其中添加 gridbagsize 并将静态文本组件放入其中时,它会获取主面板的颜色,而不是中间面板的颜色.显然我做错了什么......
I'm testing with an application. Now I want to have a nice border around the mid panel, so it's embedded in another panel. However, when I want to add a gridbagsize in it and put static text components in it, it gets the colour of the main panel, not the midpanel. Obviously I'm doing something wrong...
代码:
#Parent panel
pnl = wx.Panel(self)
pnl.SetBackgroundColour('#4f5049')
vbox = wx.BoxSizer(wx.VERTICAL)
midPan = wx.Panel(pnl)
midPan.SetBackgroundColour('#ededed')
vbox.Add(midPan,wx.ID_ANY, wx.EXPAND |wx.ALL, 20)
sizer = wx.GridBagSizer(10,5)
#sizer.
st1=wx.StaticText(pnl,label='TEST')
sizer.Add(st1, pos=(1,1),flag=wx.ALL,border=5)
midPan.SetSizer(sizer)
#vbox.Add(sizer,wx.ID_ANY, wx.EXPAND |wx.ALL, 0)
#draw application
pnl.SetSizer(vbox)
如您所见,似乎将 sizer 添加到 pnl 而不是 midPan...我做错了什么?
as you see, it looks like the sizer is added to the pnl instead of the midPan... What am I doing wrong?
推荐答案
您将 statictext 定义为 pnl 而不是 midPnl 的子项
You are defining your statictext as a child of the pnl rather than midPnl
import wx
class MyFrame(wx.Frame):
def __init__(self, parent, id=wx.ID_ANY, title="", size=(360,100)):
super(MyFrame, self).__init__(parent, id, title, size)
pnl = wx.Panel(self)
pnl.SetBackgroundColour('#4f5049')
vbox = wx.BoxSizer(wx.VERTICAL)
midPan = wx.Panel(pnl)
midPan.SetBackgroundColour('green')
vbox.Add(midPan,wx.ID_ANY, wx.EXPAND |wx.ALL, 20)
sizer = wx.GridBagSizer(10,5)
st1=wx.StaticText(midPan,label='Black on green')
st2=wx.StaticText(midPan,label='White on green')
st2.SetForegroundColour('white')
st3=wx.StaticText(midPan)
st3.SetLabelMarkup("<span foreground='black' background='red'>Black on red</span>")
st4=wx.StaticText(midPan)
st4.SetLabelMarkup("<span foreground='white' background='red'>White on red</span>")
sizer.Add(st1, pos=(1,1),flag=wx.ALL,border=5)
sizer.Add(st2, pos=(2,2),flag=wx.ALL,border=5)
sizer.Add(st3, pos=(3,3),flag=wx.ALL,border=5)
sizer.Add(st4, pos=(4,1),flag=wx.ALL,border=5)
midPan.SetSizer(sizer)
pnl.SetSizer(vbox)
self.Show()
if __name__ == "__main__":
app = wx.App()
frame = MyFrame(None,title="The Main Frame")
app.MainLoop()
这篇关于wxPython gridbagsizer 颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!