New panel activating only when window resized: WxPython

Solution 1:

In this case Layout() is your friend.
Normally Layout() is used when sizers are involved but in this case, there are no sizers but the parent is a wx.TopLevelWindow.

Layout lays out the children using the window sizer or resizes the only child of the window to cover its entire area.

wx.TopLevelWindow.Layout overrides the base class Layout method to check if this window contains exactly one child – which is commonly the case, with wx.Panel being often created as the only child of wx.TopLevelWindow – and, if this is the case, resizes this child window to cover the entire client area.

See parent.Layout() below:

import wx

class secPanel ( wx.Panel ):
    def __init__ ( self, parent ):
        wx.Panel.__init__ ( self, parent = parent )
        wx.TextCtrl ( self, pos = ( 100, 100 ) )

class mainPanel ( wx.Panel ):
    def __init__ ( self, parent ):
        wx.Panel.__init__ ( self, parent = parent )
        self.parent = parent
        b = wx.Button ( self, label = "Test", pos = ( 100, 100 ) )
        self.Bind ( wx.EVT_BUTTON, self.onPress, b )

    def onPress ( self, event ):
        parent = self.parent
        self.Destroy()
        secPanel ( parent )
        parent.Layout()

class Window ( wx.Frame ):
    def __init__ ( self ):
        wx.Frame.__init__ ( self, parent = None, title = "" )

        mainPanel ( self )
        self.Show()

if __name__ == "__main__":
    app = wx.App()
    window = Window()
    app.MainLoop()