宽大通网格袋颜色

我正在使用应用程序进行测试。现在我想在中间面板周围有一个很好的边框,所以它嵌入到另一个面板中。但是,当我想在其中添加网格袋大小并在其中放置静态文本组件时,它会获得主面板的颜色,而不是中窗格的颜色。显然我做错了什么...


法典:


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

http://img2.mukewang.com/63204dc100014f4c04530262.jpg

如您所见,看起来尺寸器被添加到pnl而不是中潘...我做错了什么?


函数式编程
浏览 41回答 1
1回答

慕桂英3389331

您正在将静态文本定义为 pnl 的子级,而不是 midPanimport wxclass MyFrame(wx.Frame):&nbsp; &nbsp; def __init__(self, parent, id=wx.ID_ANY, title="", size=(360,100)):&nbsp; &nbsp; &nbsp; &nbsp; super(MyFrame, self).__init__(parent, id, title, size)&nbsp; &nbsp; &nbsp; &nbsp; pnl = wx.Panel(self)&nbsp; &nbsp; &nbsp; &nbsp; pnl.SetBackgroundColour('#4f5049')&nbsp; &nbsp; &nbsp; &nbsp; vbox = wx.BoxSizer(wx.VERTICAL)&nbsp; &nbsp; &nbsp; &nbsp; midPan = wx.Panel(pnl)&nbsp; &nbsp; &nbsp; &nbsp; midPan.SetBackgroundColour('green')&nbsp; &nbsp; &nbsp; &nbsp; vbox.Add(midPan,wx.ID_ANY, wx.EXPAND |wx.ALL, 20)&nbsp; &nbsp; &nbsp; &nbsp; sizer = wx.GridBagSizer(10,5)&nbsp; &nbsp; &nbsp; &nbsp; st1=wx.StaticText(midPan,label='Black on green')&nbsp; &nbsp; &nbsp; &nbsp; st2=wx.StaticText(midPan,label='White on green')&nbsp; &nbsp; &nbsp; &nbsp; st2.SetForegroundColour('white')&nbsp; &nbsp; &nbsp; &nbsp; st3=wx.StaticText(midPan)&nbsp; &nbsp; &nbsp; &nbsp; st3.SetLabelMarkup("<span foreground='black' background='red'>Black on red</span>")&nbsp; &nbsp; &nbsp; &nbsp; st4=wx.StaticText(midPan)&nbsp; &nbsp; &nbsp; &nbsp; st4.SetLabelMarkup("<span foreground='white' background='red'>White on red</span>")&nbsp; &nbsp; &nbsp; &nbsp; sizer.Add(st1, pos=(1,1),flag=wx.ALL,border=5)&nbsp; &nbsp; &nbsp; &nbsp; sizer.Add(st2, pos=(2,2),flag=wx.ALL,border=5)&nbsp; &nbsp; &nbsp; &nbsp; sizer.Add(st3, pos=(3,3),flag=wx.ALL,border=5)&nbsp; &nbsp; &nbsp; &nbsp; sizer.Add(st4, pos=(4,1),flag=wx.ALL,border=5)&nbsp; &nbsp; &nbsp; &nbsp; midPan.SetSizer(sizer)&nbsp; &nbsp; &nbsp; &nbsp; pnl.SetSizer(vbox)&nbsp; &nbsp; &nbsp; &nbsp; self.Show()if __name__ == "__main__":&nbsp; &nbsp; app = wx.App()&nbsp; &nbsp; frame = MyFrame(None,title="The Main Frame")&nbsp; &nbsp; app.MainLoop()
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python