为什么这个 StaticLine 出现在 sizer 后面?

Why does this StaticLine appear behind the sizer?

我试图在 "Label"+TextCtrl 和单选按钮之间画一条静态线。 它只在拖动 window 时一直出现,然后它出现在所有内容的后面,我不明白为什么。

目标是在上部和下部之间水平绘制静态线。

import wx

class MyFrame(wx.Frame):
    def __init__(self, *args, **kwds):
        # begin wxGlade: MyFrame.__init__
        wx.Frame.__init__(self, *args, **kwds)
        self.SetSize((237, 237))

    self.__initUI()
    self.__do_layout()

def __initUI(self):

    panel = wx.Panel(self)
    self.SetSize((350, 150))
    self.qtyField = wx.TextCtrl(panel, wx.ID_ANY, "", style=wx.TE_CENTER)
    self.qtyField.SetFocus()
    self.longRb = wx.RadioButton(panel, wx.ID_ANY, "This", style=wx.RB_GROUP)
    self.shortRb = wx.RadioButton(panel, wx.ID_ANY, "That")

def __do_layout(self):
    # begin wxGlade: MyFrame.__do_layout
    vertSizer = wx.BoxSizer(wx.VERTICAL)
    horSizer1 = wx.GridSizer(1, 2, 0, 0)
    rbSizer = wx.GridSizer(1, 2, 0, 36)

    qtyLabel = wx.StaticText(self, wx.ID_ANY, "Label")
    horSizer1.Add(qtyLabel, 0, wx.ALIGN_CENTER, 0)
    horSizer1.Add(self.qtyField, 0, wx.ALIGN_CENTER_VERTICAL, 0)
    vertSizer.Add(horSizer1, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.BOTTOM | wx.TOP, 6)

    static_line_1 = wx.StaticLine(self, wx.ID_ANY)
    vertSizer.Add(static_line_1, 0, wx.EXPAND | wx.LEFT | wx.RIGHT, 6)

    rbSizer.Add(self.longRb, 0, wx.ALIGN_CENTER, 0)
    rbSizer.Add(self.shortRb, 0, wx.ALIGN_CENTER, 0)
    vertSizer.Add(rbSizer, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.BOTTOM | wx.TOP, 6)

    self.SetSizer(vertSizer)


class MyApp(wx.App):
    def OnInit(self):
        self.frame = MyFrame(None, wx.ID_ANY, "")
        self.SetTopWindow(self.frame)
        self.frame.Show()
        return True

# end of class MyApp

if __name__ == "__main__":
    app = MyApp(0)
    app.MainLoop()

您正在将一些小部件分配给框架(自身),将其他小部件分配给面板,因此它们会按照指示显示自己。

这就是你想要的:

import wx

class MyFrame(wx.Frame):
    def __init__(self, *args, **kwds):
        # begin wxGlade: MyFrame.__init__
        wx.Frame.__init__(self, *args, **kwds)
        self.SetSize((237, 237))

        self.__initUI()
        self.__do_layout()

    def __initUI(self):

        self.panel = wx.Panel(self)
        self.panel.SetBackgroundColour("green")
        self.SetSize((350, 150))
        self.qtyField = wx.TextCtrl(self.panel, wx.ID_ANY, "", style=wx.TE_CENTER)
        self.qtyField.SetFocus()
        self.longRb = wx.RadioButton(self.panel, wx.ID_ANY, "This", style=wx.RB_GROUP)
        self.shortRb = wx.RadioButton(self.panel, wx.ID_ANY, "That")

    def __do_layout(self):
        # begin wxGlade: MyFrame.__do_layout
        vertSizer = wx.BoxSizer(wx.VERTICAL)
        horSizer1 = wx.GridSizer(1, 2, 0, 0)
        rbSizer = wx.GridSizer(1, 2, 0, 36)

        qtyLabel = wx.StaticText(self.panel, wx.ID_ANY, "Label")
        horSizer1.Add(qtyLabel, 0, wx.ALIGN_CENTER, 0)
        horSizer1.Add(self.qtyField, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        vertSizer.Add(horSizer1, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.BOTTOM | wx.TOP, 6)

        static_line_1 = wx.StaticLine(self.panel, wx.ID_ANY)
        vertSizer.Add(static_line_1, 0, wx.EXPAND | wx.LEFT | wx.RIGHT, 6)

        rbSizer.Add(self.longRb, 0, wx.ALIGN_CENTER, 0)
        rbSizer.Add(self.shortRb, 0, wx.ALIGN_CENTER, 0)
        vertSizer.Add(rbSizer, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.BOTTOM | wx.TOP, 6)

        self.SetSizer(vertSizer)


class MyApp(wx.App):
    def OnInit(self):
        self.frame = MyFrame(None, wx.ID_ANY, "")
        self.SetTopWindow(self.frame)
        self.frame.Show()
        return True

# end of class MyApp

if __name__ == "__main__":
    app = MyApp(0)
    app.MainLoop()