Question

I'm trying to show a full screen app with three panels. The screen should be divided first in two vertical panels, and the right one in two horizontals. Something like:

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

The problem is that I don't get that, since I have some problems with sizers. This is my attempt:

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()
Was it helpful?

Solution

Remove following two lines:

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

with:

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

What's wrong with those lines:

  1. In the first line, the code is passing main_splitter to main_splitter.SplitVertically.
  2. The second line splits main_splitter again.

And remove following lines:

# 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)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top