Search code examples
pythonpython-3.xwxpythonsizerboxsizer

Boxsizers in a New Panel


I have a menubar item that activates the following function. A new window should popup, but I am having trouble placing sizers within the new window. I would prefer to create the window under the Class Parameter1Window, but I keep getting the variable not defined message. I have also tried creating a panel within the function with no success. What am I doing wrong?enter code here

Also open to suggestions on the overall structure.

def onParam1(self, event):

    self.frame = wx.Frame(None, -1, "Browse Lookup Sources")
    p1Panel = wx.Panel(self.frame,-1)

    #Create Objects
    pw1_st1 = wx.StaticText(p1Panel, -1,"NAME")
    pw1_st2 = wx.StaticText(p1Panel, -1,"File Path")
    pw1_st3 = wx.StaticText(p1Panel, -1,"Rows")
    pw1_st4 = wx.StaticText(self.frame, -1,"Columns")

    #Create Sizers
    self.pw1_hbox1 = wx.BoxSizer(wx.HORIZONTAL) 
    self.pw1_vbox1 = wx.BoxSizer(wx.VERTICAL) 
    self.pw1_mainsizer = wx.BoxSizer(wx.VERTICAL)

    #Add to Layout
    self.pw1_hbox1.Add(pw1_st1, flag=wx.ALL, border=5)
    self.pw1_hbox1.Add(pw1_st2, flag=wx.ALL, border=5)
    self.pw1_hbox1.Add(pw1_st3, flag=wx.ALL, border=5)
    self.pw1_hbox1.Add(pw1_st4, flag=wx.ALL, border=5)

    #self.pw1_vbox1.Add(self.pw1_hbox1, flag=wx.ALL, border=5)


    self.pw1_mainsizer.Add(self.pw1_hbox1, 1, wx.EXPAND)
    self.SetSizer(self.pw1_mainsizer)

    self.frame.Center()
    self.frame.Show()

#----------------------------------------------------------------------
def onParam2(self, event):

    print("Parameter 2 chosen")


class Parameter1Window(wx.Frame):

def __init__(self):
     wx.Frame.__init__(self, parent, 5, size=(400,400))
     wx.Frame.CenterOnScreen(self)

def main():
    ex = wx.App(redirect=False)
    MainFrame(None)
    ex.MainLoop()    


# Run the program
if __name__ == "__main__":
    app = wx.App(False)
    frame = MainFrame()
    frame.Show()
    app.MainLoop()`

The complete code:

import wx
import wx.grid as gridlib
import pandas as pd
import numpy as np

class OptionsDialog(wx.Dialog):
""""""

#----------------------------------------------------------------------
def __init__(self):
    """Constructor"""
    wx.Dialog.__init__(self, None, title="Options")

    radio1 = wx.RadioButton( self, -1, " Radio1 ", style = wx.RB_GROUP )
    radio2 = wx.RadioButton( self, -1, " Radio2 " )
    radio3 = wx.RadioButton( self, -1, " Radio3 " )

    sizer = wx.BoxSizer(wx.VERTICAL)
    sizer.Add(radio1, 0, wx.ALL, 5)
    sizer.Add(radio2, 0, wx.ALL, 5)
    sizer.Add(radio3, 0, wx.ALL, 5)

    for i in range(3):
        chk = wx.CheckBox(self, label="Checkbox #%s" % (i+1))
        sizer.Add(chk, 0, wx.ALL, 5)
    self.SetSizer(sizer)



########################################################################
class TopPanel(wx.Panel):
""""""
#----------------------------------------------------------------------
def __init__(self, parent):
    """Constructor"""
    wx.Panel.__init__(self, parent=parent)




    #TopPanel Validation Lists:
    t_options_Source= ['Weld Tracker','TPSL','Line List','MTR Log','Master Dwg. List']
    t_options_Lookup= ['Weld','ISO','Package','Sub System', 'Report #','Stencil', 'MTR #', 'HT #', 
    'IMPORT WORKBOOK']

    #Create Objects
    self.font = wx.SystemSettings.GetFont(wx.SYS_SYSTEM_FONT)


    self.t_st1 = wx.StaticText(self, -1,"From Source:")
    self.t_st1.SetFont(self.font)
    self.t_st1.SetForegroundColour(wx.Colour(255,255,255))
    self.t_st2 = wx.StaticText(self, -1,"Lookup:")
    self.t_st2.SetFont(self.font)
    self.t_st2.SetForegroundColour(wx.Colour(255,255,255))
    self.t_st3 = wx.StaticText(self, -1,"Lookup Value:")
    self.t_st3.SetFont(self.font)
    self.t_st3.SetForegroundColour(wx.Colour(255,255,255))
    self.t_tc1 = wx.TextCtrl(self)
    self.t_tc1.SetHint('-search-')
    self.t_combo1 = wx.ComboBox(self,size=(150,25),choices=t_options_Source, style=wx.LB_SINGLE)
    self.t_combo1.SetHint('-Choose Source-')
    self.t_combo2 = wx.ComboBox(self,size=(150,25),choices=t_options_Lookup,
    style=wx.LB_SINGLE)
    self.t_combo2.SetHint('-Choose Lookup Type-')
    self.t_grid = gridlib.Grid(self)
    self.t_grid.CreateGrid(20,27)

    #Create Sizers
    self.t_hbox1 = wx.BoxSizer(wx.HORIZONTAL) 
    self.t_hbox2 = wx.BoxSizer(wx.HORIZONTAL) 
    self.t_vbox1 = wx.BoxSizer(wx.VERTICAL)
    self.mainsizer_top = wx.BoxSizer(wx.VERTICAL)

    #Add to Panel
    self.t_hbox1.Add(self.t_st1, flag=wx.ALL, border=5)
    self.t_hbox1.Add(self.t_combo1, flag=wx.ALL, border=5)
    self.t_hbox1.Add(self.t_st2, flag=wx.ALL, border=5)
    self.t_hbox1.Add(self.t_combo2, flag=wx.ALL, border=5)
    self.t_hbox2.Add(self.t_st3, flag=wx.ALL, border=5)
    self.t_hbox2.Add(self.t_tc1, flag=wx.ALL, border=5)

    self.t_vbox1.Add(self.t_hbox1, flag=wx.ALL, border=5)
    self.t_vbox1.Add(self.t_hbox2, flag=wx.ALL, border=5)
    self.t_vbox1.Add(self.t_grid, 0, wx.EXPAND)

    self.mainsizer_top.Add(self.t_vbox1, 1, wx.EXPAND)
    self.SetSizer(self.mainsizer_top)



########################################################################
class BottomPanel(wx.Panel):
""""""
#----------------------------------------------------------------------
def __init__(self, parent):
    """Constructor"""
    wx.Panel.__init__(self, parent=parent)


    #Bottom Panel Validation Lists:
    b_options_Source= ['Weld Tracker','TPSL','Line List','MTR Log','Master Dwg. List']


    #Create Objects
    self.b_st1 = wx.StaticText(self, -1,"Data Source:")
    self.b_combo1 = wx.ComboBox(self,size=(150,25),choices=b_options_Source, style=wx.LB_SINGLE)
    self.b_st2 = wx.StaticText(self, -1,"Input: ")
    self.b_tc1 = wx.TextCtrl(self, style=wx.TE_PROCESS_ENTER)
    self.b_btn1 = wx.Button(self, label="Update Data")
    #self.b_btn1.Bind(wx.EVT_BUTTON, self.onParam1)
    self.b_btn2 = wx.Button(self, label="Clear Grid") 
    #self.b_button2.Bind(wx.EVT_BUTTON, self.clear_bottom)
    self.b_btn3 = wx.Button(self, label="Delete Last Entry") 

    self.b_grid = gridlib.Grid(self)
    self.b_grid.CreateGrid(20,27)

    #Create sizers
    self.b_hbox1 = wx.BoxSizer(wx.HORIZONTAL) 
    self.b_hbox2 = wx.BoxSizer(wx.HORIZONTAL) 
    self.b_hbox3 = wx.BoxSizer(wx.HORIZONTAL) 
    self.b_vbox1 = wx.BoxSizer(wx.VERTICAL)
    self.mainsizer_bottom = wx.BoxSizer(wx.VERTICAL)

    #Add to panel
    self.b_hbox1.Add(self.b_btn1, flag=wx.ALL, border=5)
    self.b_hbox1.Add(self.b_st1, flag=wx.ALL, border=5)
    self.b_hbox1.Add(self.b_combo1, flag=wx.ALL, border=5)
    self.b_hbox2.Add(self.b_btn2, flag=wx.ALL, border=5)
    self.b_hbox2.Add(self.b_st2, flag=wx.ALL, border=5)
    self.b_hbox2.Add(self.b_tc1, flag=wx.ALL, border=5)
    self.b_hbox3.Add(self.b_btn3, flag=wx.ALL, border=5)

    self.b_vbox1.Add(self.b_hbox1, flag=wx.ALL, border=5)
    self.b_vbox1.Add(self.b_hbox2, flag=wx.ALL, border=5)
    self.b_vbox1.Add(self.b_hbox3, flag=wx.ALL, border=5)
    self.b_vbox1.Add(self.b_grid, 0, wx.EXPAND)
    self.mainsizer_bottom.Add(self.b_vbox1, 1, wx.EXPAND)
    #self.mainsizer_bottom.Add(self.b_vbox2, 1, wx.EXPAND)
    self.SetSizer(self.mainsizer_bottom)
    #self.SetSizer(b_sizer)

   ########################################################################
class MainFrame(wx.Frame):

#----------------------------------------------------------------------
def __init__(self, *args, **kwargs):
    super(MainFrame, self).__init__(*args, **kwargs) 
    self.Maximize(True)    

    self.InitUI()
def __init__(self):
    wx.Frame.__init__(self, None, title="Architekt Application",
                      size=(600,600)) #1600,1700
    #Add Menubar
    menuBar = wx.MenuBar()
    fileMenu = wx.Menu()


    optionsItem = fileMenu.Append(wx.NewIdRef(count=1), "Options", 
                                  "Show an Options Dialog")
    self.Bind(wx.EVT_MENU, self.onOptions, optionsItem)

    #Create Parameter Menu Item & SubMenu
    parameters_sub = wx.Menu()

    parameter1 = parameters_sub.Append(wx.ID_ANY,'Set Lookup Sources')
    self.Bind(wx.EVT_MENU, self.onParam1, parameter1)

    parameter2 = parameters_sub.Append(wx.ID_ANY,'Set Data Entry Sources')
    self.Bind(wx.EVT_MENU, self.onParam2, parameter2)

    #Add Parameter SubMenu
    fileMenu.AppendSubMenu(parameters_sub, 'Parameters')

    #Add Exit Menu Item
    exitMenuItem = fileMenu.Append(wx.NewIdRef(count=1), "Exit",
                                   "Exit the application")
    self.Bind(wx.EVT_MENU, self.onExit, exitMenuItem)
    #Add Save Menu Item,
    saveMenuItem = fileMenu.Append(wx.NewIdRef(count=1), "Save",
                                   "Save Application")
    #self.Bind(wx.EVT_MENU, self.onParam1, saveMenuItem)
    #Create MenuBar
    menuBar.Append(fileMenu, "&File")
    self.SetMenuBar(menuBar)

    #Create Panels
    splitter = wx.SplitterWindow(self)
    topP = TopPanel(splitter)
    bottomP = BottomPanel(splitter)

    #Set Panel Colors
    topP.SetBackgroundColour(wx.Colour(32,55,100))
    bottomP.SetBackgroundColour(wx.Colour(214,220,228))

    # split the window
    splitter.SplitHorizontally(topP, bottomP)
    splitter.SetMinimumPaneSize(200)

    sizer = wx.BoxSizer(wx.VERTICAL)
    sizer.Add(splitter, 1, wx.EXPAND)
    self.SetSizer(sizer)
#----------------------------------------------------------------------
def onExit(self, event):

    self.Close()

#----------------------------------------------------------------------
def onOptions(self, event):

    dlg = OptionsDialog()
    dlg.ShowModal()
    dlg.Destroy()
#----------------------------------------------------------------------
def onParam1(self, event):

    self.frame = wx.Frame(None, -1, "Browse Lookup Sources")
    p1Panel = wx.Panel(self.frame,-1)

    #Create Objects
    pw1_st1 = wx.StaticText(p1Panel, -1,"NAME")
    pw1_st2 = wx.StaticText(p1Panel, -1,"File Path")
    pw1_st3 = wx.StaticText(p1Panel, -1,"Rows")
    pw1_st4 = wx.StaticText(self.frame, -1,"Columns")

    #Create Sizers
    self.pw1_hbox1 = wx.BoxSizer(wx.HORIZONTAL) 
    self.pw1_vbox1 = wx.BoxSizer(wx.VERTICAL) 
    self.pw1_mainsizer = wx.BoxSizer(wx.VERTICAL)

    #Add to Layout
    self.pw1_hbox1.Add(pw1_st1, flag=wx.ALL, border=5)
    self.pw1_hbox1.Add(pw1_st2, flag=wx.ALL, border=5)
    self.pw1_hbox1.Add(pw1_st3, flag=wx.ALL, border=5)
    self.pw1_hbox1.Add(pw1_st4, flag=wx.ALL, border=5)

    self.pw1_vbox1.Add(self.pw1_hbox1, flag=wx.ALL, border=5)


    self.pw1_mainsizer.Add(self.pw1_hbox1, 1, wx.EXPAND)
    self.SetSizer(self.pw1_mainsizer)

    self.frame.Center()
    self.frame.Show()

#----------------------------------------------------------------------
def onParam2(self, event):

    print("Parameter 2 chosen")

#----------------------------------------------------------------------
class Parameter1Window(wx.Frame):

def __init__(self):
     wx.Frame.__init__(self, parent, 5, size=(400,400))
     wx.Frame.CenterOnScreen(self)

def main():
    ex = wx.App(redirect=False)
    MainFrame(None)
    ex.MainLoop()    


# Run the program
if __name__ == "__main__":
app = wx.App(False)
frame = MainFrame()
frame.Show()
app.MainLoop()

Solution

  • The easiest way to resolve this is to make it a separate class and then call that from the menu event callback.

    See the definition onParam1 in the MainFrame class and the new class Param1

    As a separate class it will need its own Quit function, so that it can be destroyed.
    A button is handy but never forget the X in the top righthand corner of the window.
    It fires the wx.EVT_CLOSE event.

    import wx
    import wx.grid as gridlib
    import pandas as pd
    import numpy as np
    
    class OptionsDialog(wx.Dialog):
    
        #----------------------------------------------------------------------
        def __init__(self):
            """Constructor"""
            wx.Dialog.__init__(self, None, title="Options")
    
            radio1 = wx.RadioButton( self, -1, " Radio1 ", style = wx.RB_GROUP )
            radio2 = wx.RadioButton( self, -1, " Radio2 " )
            radio3 = wx.RadioButton( self, -1, " Radio3 " )
    
            sizer = wx.BoxSizer(wx.VERTICAL)
            sizer.Add(radio1, 0, wx.ALL, 5)
            sizer.Add(radio2, 0, wx.ALL, 5)
            sizer.Add(radio3, 0, wx.ALL, 5)
    
            for i in range(3):
                chk = wx.CheckBox(self, label="Checkbox #%s" % (i+1))
                sizer.Add(chk, 0, wx.ALL, 5)
            self.SetSizer(sizer)
    
    
    
    ########################################################################
    class TopPanel(wx.Panel):
        #----------------------------------------------------------------------
        def __init__(self, parent):
            """Constructor"""
            wx.Panel.__init__(self, parent=parent)
    
    
    
    
            #TopPanel Validation Lists:
            t_options_Source= ['Weld Tracker','TPSL','Line List','MTR Log','Master Dwg. List']
            t_options_Lookup= ['Weld','ISO','Package','Sub System', 'Report #','Stencil', 'MTR #', 'HT #',
            'IMPORT WORKBOOK']
    
            #Create Objects
            self.font = wx.SystemSettings.GetFont(wx.SYS_SYSTEM_FONT)
    
    
            self.t_st1 = wx.StaticText(self, -1,"From Source:")
            self.t_st1.SetFont(self.font)
            self.t_st1.SetForegroundColour(wx.Colour(255,255,255))
            self.t_st2 = wx.StaticText(self, -1,"Lookup:")
            self.t_st2.SetFont(self.font)
            self.t_st2.SetForegroundColour(wx.Colour(255,255,255))
            self.t_st3 = wx.StaticText(self, -1,"Lookup Value:")
            self.t_st3.SetFont(self.font)
            self.t_st3.SetForegroundColour(wx.Colour(255,255,255))
            self.t_tc1 = wx.TextCtrl(self)
            self.t_tc1.SetHint('-search-')
            self.t_combo1 = wx.ComboBox(self,size=(150,25),choices=t_options_Source, style=wx.LB_SINGLE)
            self.t_combo1.SetHint('-Choose Source-')
            self.t_combo2 = wx.ComboBox(self,size=(150,25),choices=t_options_Lookup,
            style=wx.LB_SINGLE)
            self.t_combo2.SetHint('-Choose Lookup Type-')
            self.t_grid = gridlib.Grid(self)
            self.t_grid.CreateGrid(20,27)
    
            #Create Sizers
            self.t_hbox1 = wx.BoxSizer(wx.HORIZONTAL)
            self.t_hbox2 = wx.BoxSizer(wx.HORIZONTAL)
            self.t_vbox1 = wx.BoxSizer(wx.VERTICAL)
            self.mainsizer_top = wx.BoxSizer(wx.VERTICAL)
    
            #Add to Panel
            self.t_hbox1.Add(self.t_st1, flag=wx.ALL, border=5)
            self.t_hbox1.Add(self.t_combo1, flag=wx.ALL, border=5)
            self.t_hbox1.Add(self.t_st2, flag=wx.ALL, border=5)
            self.t_hbox1.Add(self.t_combo2, flag=wx.ALL, border=5)
            self.t_hbox2.Add(self.t_st3, flag=wx.ALL, border=5)
            self.t_hbox2.Add(self.t_tc1, flag=wx.ALL, border=5)
    
            self.t_vbox1.Add(self.t_hbox1, flag=wx.ALL, border=5)
            self.t_vbox1.Add(self.t_hbox2, flag=wx.ALL, border=5)
            self.t_vbox1.Add(self.t_grid, 0, wx.EXPAND)
    
            self.mainsizer_top.Add(self.t_vbox1, 1, wx.EXPAND)
            self.SetSizer(self.mainsizer_top)
    
    
    
    ########################################################################
    class BottomPanel(wx.Panel):
        #----------------------------------------------------------------------
        def __init__(self, parent):
            """Constructor"""
            wx.Panel.__init__(self, parent=parent)
    
    
            #Bottom Panel Validation Lists:
            b_options_Source= ['Weld Tracker','TPSL','Line List','MTR Log','Master Dwg. List']
    
    
            #Create Objects
            self.b_st1 = wx.StaticText(self, -1,"Data Source:")
            self.b_combo1 = wx.ComboBox(self,size=(150,25),choices=b_options_Source, style=wx.LB_SINGLE)
            self.b_st2 = wx.StaticText(self, -1,"Input: ")
            self.b_tc1 = wx.TextCtrl(self, style=wx.TE_PROCESS_ENTER)
            self.b_btn1 = wx.Button(self, label="Update Data")
            #self.b_btn1.Bind(wx.EVT_BUTTON, self.onParam1)
            self.b_btn2 = wx.Button(self, label="Clear Grid")
            #self.b_button2.Bind(wx.EVT_BUTTON, self.clear_bottom)
            self.b_btn3 = wx.Button(self, label="Delete Last Entry")
    
            self.b_grid = gridlib.Grid(self)
            self.b_grid.CreateGrid(20,27)
    
            #Create sizers
            self.b_hbox1 = wx.BoxSizer(wx.HORIZONTAL)
            self.b_hbox2 = wx.BoxSizer(wx.HORIZONTAL)
            self.b_hbox3 = wx.BoxSizer(wx.HORIZONTAL)
            self.b_vbox1 = wx.BoxSizer(wx.VERTICAL)
            self.mainsizer_bottom = wx.BoxSizer(wx.VERTICAL)
    
            #Add to panel
            self.b_hbox1.Add(self.b_btn1, flag=wx.ALL, border=5)
            self.b_hbox1.Add(self.b_st1, flag=wx.ALL, border=5)
            self.b_hbox1.Add(self.b_combo1, flag=wx.ALL, border=5)
            self.b_hbox2.Add(self.b_btn2, flag=wx.ALL, border=5)
            self.b_hbox2.Add(self.b_st2, flag=wx.ALL, border=5)
            self.b_hbox2.Add(self.b_tc1, flag=wx.ALL, border=5)
            self.b_hbox3.Add(self.b_btn3, flag=wx.ALL, border=5)
    
            self.b_vbox1.Add(self.b_hbox1, flag=wx.ALL, border=5)
            self.b_vbox1.Add(self.b_hbox2, flag=wx.ALL, border=5)
            self.b_vbox1.Add(self.b_hbox3, flag=wx.ALL, border=5)
            self.b_vbox1.Add(self.b_grid, 0, wx.EXPAND)
            self.mainsizer_bottom.Add(self.b_vbox1, 1, wx.EXPAND)
            #self.mainsizer_bottom.Add(self.b_vbox2, 1, wx.EXPAND)
            self.SetSizer(self.mainsizer_bottom)
            #self.SetSizer(b_sizer)
    
       ########################################################################
    class MainFrame(wx.Frame):
    
        #----------------------------------------------------------------------
        def __init__(self, *args, **kwargs):
            super(MainFrame, self).__init__(*args, **kwargs)
            self.Maximize(True)
    
            self.InitUI()
        def __init__(self):
            wx.Frame.__init__(self, None, title="Architekt Application",
                              size=(600,600)) #1600,1700
            #Add Menubar
            menuBar = wx.MenuBar()
            fileMenu = wx.Menu()
    
    
            optionsItem = fileMenu.Append(wx.NewIdRef(count=1), "Options",
                                          "Show an Options Dialog")
            self.Bind(wx.EVT_MENU, self.onOptions, optionsItem)
    
            #Create Parameter Menu Item & SubMenu
            parameters_sub = wx.Menu()
    
            parameter1 = parameters_sub.Append(wx.ID_ANY,'Set Lookup Sources')
            self.Bind(wx.EVT_MENU, self.onParam1, parameter1)
    
            parameter2 = parameters_sub.Append(wx.ID_ANY,'Set Data Entry Sources')
            self.Bind(wx.EVT_MENU, self.onParam2, parameter2)
    
            #Add Parameter SubMenu
            fileMenu.AppendSubMenu(parameters_sub, 'Parameters')
    
            #Add Exit Menu Item
            exitMenuItem = fileMenu.Append(wx.NewIdRef(count=1), "Exit",
                                           "Exit the application")
            self.Bind(wx.EVT_MENU, self.onExit, exitMenuItem)
            #Add Save Menu Item,
            saveMenuItem = fileMenu.Append(wx.NewIdRef(count=1), "Save",
                                           "Save Application")
            #self.Bind(wx.EVT_MENU, self.onParam1, saveMenuItem)
            #Create MenuBar
            menuBar.Append(fileMenu, "&File")
            self.SetMenuBar(menuBar)
    
            #Create Panels
            splitter = wx.SplitterWindow(self)
            topP = TopPanel(splitter)
            bottomP = BottomPanel(splitter)
    
            #Set Panel Colors
            topP.SetBackgroundColour(wx.Colour(32,55,100))
            bottomP.SetBackgroundColour(wx.Colour(214,220,228))
    
            # split the window
            splitter.SplitHorizontally(topP, bottomP)
            splitter.SetMinimumPaneSize(200)
    
            sizer = wx.BoxSizer(wx.VERTICAL)
            sizer.Add(splitter, 1, wx.EXPAND)
            self.SetSizer(sizer)
        #----------------------------------------------------------------------
        def onExit(self, event):
    
            self.Close()
    
        #----------------------------------------------------------------------
        def onOptions(self, event):
    
            dlg = OptionsDialog()
            dlg.ShowModal()
            dlg.Destroy()
        #----------------------------------------------------------------------
        def onParam1(self, event):
            x = Param1(parent=self)
    
        #----------------------------------------------------------------------
        def onParam2(self, event):
    
            print("Parameter 2 chosen")
    
    #----------------------------------------------------------------------
    class Param1(wx.Frame):
        def __init__(self, parent):
            wx.Frame.__init__(self, parent, -1, "Browse Lookup Sources", size=(400,400))
            self.p1Panel = wx.Panel(self)
    
            #Create Objects
            pw1_st1 = wx.StaticText(self.p1Panel, -1,"NAME")
            pw1_st2 = wx.StaticText(self.p1Panel, -1,"File Path")
            pw1_st3 = wx.StaticText(self.p1Panel, -1,"Rows")
            pw1_st4 = wx.StaticText(self.p1Panel, -1,"Columns")
    
            pw1_btn_quit = wx.Button(self.p1Panel, -1,"Quit")
    
    
            #Create Sizers
            self.pw1_hbox1 = wx.BoxSizer(wx.HORIZONTAL)
            self.pw1_vbox1 = wx.BoxSizer(wx.VERTICAL)
            self.pw1_mainsizer = wx.BoxSizer(wx.VERTICAL)
    
            #Add to Layout
            self.pw1_hbox1.Add(pw1_st1, flag=wx.ALL, border=5)
            self.pw1_hbox1.Add(pw1_st2, flag=wx.ALL, border=5)
            self.pw1_hbox1.Add(pw1_st3, flag=wx.ALL, border=5)
            self.pw1_hbox1.Add(pw1_st4, flag=wx.ALL, border=5)
    
            self.pw1_vbox1.Add(self.pw1_hbox1, flag=wx.ALL, border=5)
            self.pw1_vbox1.Add(pw1_btn_quit, flag=wx.ALL, border=5)
            self.Bind(wx.EVT_CLOSE, self.OnQuit)
            pw1_btn_quit.Bind(wx.EVT_BUTTON, self.OnQuit)
    
            self.pw1_mainsizer.Add(self.pw1_vbox1, 1, wx.EXPAND)
            self.p1Panel.SetSizer(self.pw1_mainsizer)
    
            self.Show()
    
        def OnQuit(self, event):
            self.Destroy()
    
    class Parameter1Window(wx.Frame):
    
        def __init__(self):
             wx.Frame.__init__(self, parent, 5, size=(400,400))
             wx.Frame.CenterOnScreen(self)
    
        def main():
            ex = wx.App(redirect=False)
            MainFrame(None)
            ex.MainLoop()
    
    
    # Run the program
    if __name__ == "__main__":
        app = wx.App(False)
        frame = MainFrame()
        frame.Show()
        app.MainLoop()
    

    enter image description here