0

我正在尝试显示具有三个面板的全屏应用程序。屏幕应该首先分成两个垂直面板,右边的一个分成两个水平面板。就像是:

____________________
|        |         |
|        |         |
|        |_________|
|        |         |
|        |         |
|________|_________|

问题是我不明白,因为我对sizer有一些问题。这是我的尝试:

import wx

class Input_Panel(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent)
        # Input variables
        self.tittle1 = wx.StaticText(self, label="Inputs:")    
        self.lblname1 = wx.StaticText(self, label="Input 1:")
        self.format1 = ['Option 1','Option 2']
        self.combo1 = wx.ComboBox(self, size=(200, -1),value='', choices=self.format1,style=wx.CB_DROPDOWN)
        self.lblname2 = wx.StaticText(self, label="Input 2")
        self.format2 = ['Option 1','Option 2', 'Option 3']
        self.combo2 = wx.ComboBox(self, size=(200, -1),value='', choices=self.format2, style=wx.CB_DROPDOWN)

        # Set sizer for the panel content
        self.sizer = wx.GridBagSizer(2, 2)
        self.sizer.Add(self.tittle1, (1, 2))
        self.sizer.Add(self.lblname1, (2, 1))
        self.sizer.Add(self.combo1, (2, 2))
        self.sizer.Add(self.lblname2, (3, 1))
        self.sizer.Add(self.combo2, (3, 2))
        self.SetSizer(self.sizer)

class Output_Panel1(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent)
        # Output variables
        self.tittle2 = wx.StaticText(self, label="Outputs:")    
        self.lblname3 = wx.StaticText(self, label="Output1")
        self.result3 = wx.StaticText(self, label="", size=(100, -1))

        # Set sizer for the panel content
        self.sizer = wx.GridBagSizer(2, 2)
        self.sizer.Add(self.tittle2, (1, 2))
        self.sizer.Add(self.lblname3, (2, 1))
        self.sizer.Add(self.result3, (2, 2))
        self.SetSizer(self.sizer)

class Output_Panel2(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent)
        # Output variables
        self.tittle2 = wx.StaticText(self, label="Outputs:")    
        self.lblname3 = wx.StaticText(self, label="Output1")
        self.result3 = wx.StaticText(self, label="", size=(100, -1))

        # Set sizer for the panel content
        self.sizer = wx.GridBagSizer(2, 2)
        self.sizer.Add(self.tittle2, (1, 2))
        self.sizer.Add(self.lblname3, (2, 1))
        self.sizer.Add(self.result3, (2, 2))
        self.SetSizer(self.sizer)



class Main_Window(wx.Frame):
    def __init__(self, parent, title):
        wx.Frame.__init__(self, parent, title = title, pos = (0, 0), size = wx.DisplaySize())

        # Set variable panels
        self.main_splitter = wx.SplitterWindow(self)
        self.out_splitter = wx.SplitterWindow(self.main_splitter)
        self.inputpanel = Input_Panel(self.main_splitter)
        self.inputpanel.SetBackgroundColour('#c4c4ff')
        self.outputpanel1 = Output_Panel1(self.out_splitter)
        self.outputpanel1.SetBackgroundColour('#c2f1f5')
        self.outputpanel2 = Output_Panel2(self.out_splitter)
        self.outputpanel2.SetBackgroundColour('#c2f1f5')
        self.main_splitter.SplitVertically(self.inputpanel, self.main_splitter)
        self.main_splitter.SplitHorizontally(self.outputpanel1, self.outputpanel2)

        # Set sizers
        self.windowSizer1 = wx.BoxSizer(wx.VERTICAL)
        self.windowSizer2 = wx.BoxSizer(wx.HORIZONTAL)
        self.windowSizer2.Add(self.out_splitter, 1, wx.ALL | wx.EXPAND)
        self.windowSizer1.Add(self.windowSizer2, 1, wx.ALL | wx.EXPAND)    
        self.SetSizer(self.windowSizer1)

def main():
    app = wx.App(False)
    frame = Main_Window(None, "App GUI")
    frame.Show()
    app.MainLoop()

if __name__ == "__main__" :
    main()
4

1 回答 1

3

删除以下两行:

self.main_splitter.SplitVertically(self.inputpanel, self.main_splitter)
self.main_splitter.SplitHorizontally(self.outputpanel1, self.outputpanel2)

和:

self.main_splitter.SplitVertically(self.inputpanel, self.out_splitter)
self.out_splitter.SplitHorizontally(self.outputpanel1, self.outputpanel2)

这些行有什么问题

  1. 在第一行,代码传递main_splittermain_splitter.SplitVertically.
  2. 第二行main_splitter再次分裂。

并删除以下行:

# Set sizers
self.windowSizer1 = wx.BoxSizer(wx.VERTICAL)
self.windowSizer2 = wx.BoxSizer(wx.HORIZONTAL)
self.windowSizer2.Add(self.out_splitter, 1, wx.ALL | wx.EXPAND)
self.windowSizer1.Add(self.windowSizer2, 1, wx.ALL | wx.EXPAND)    
self.SetSizer(self.windowSizer1)
于 2013-10-17T15:10:13.657 回答