The size changes of frame and panel are not synchronized

I have an aui management framework with many panels. I found that when the frame was maximized, the size change of the panel was not consistent with the actual display. For example, if the frame size is (930,311) and the panel size is (0, 0) during initialization, the actual panel size should be (720,400). When maximized, the frame is (1536,801) and the panel is (726,290), while the actual display size of the panel is (1328,400). Panel size is always one change behind. Why is this?
class CanvasFrame(wx.Frame):
def init(self, ):
wx.Frame.init(self,None, -1, ‘CanvasFrame’, size=(950, 350))

    self.pnl=wx.Panel(self)            
   
    self.gridPanel = wx.Panel(self.pnl,-1)
    grid = wx.grid.Grid(self.gridPanel, -1, wx.Point(0, 0),size=(400,100),style=wx.NO_BORDER | wx.WANTS_CHARS)
    grid.CreateGrid(500, 15)

    search_window=wx.Panel(self.gridPanel,-1)
    search_value=wx.TextCtrl(search_window,-1)
    searchBox=wx.BoxSizer(wx.HORIZONTAL)
    searchBox.Add(search_value,6,wx.LEFT,1)
    searchBox.Add(wx.Button(search_window,-1,label="GO"),1,wx.LEFT, 5)
    search_window.SetSizer(searchBox)
  
    leftBox = wx.BoxSizer(wx.VERTICAL)
    leftBox.Add(grid, 40, wx.EXPAND)
    leftBox.Add(wx.StaticText(self.gridPanel, label = "search:"), 1, wx.LEFT, 60)
    leftBox.Add(search_window,3,wx.LEFT)        
          
    self.gridPanel.SetSizer(leftBox)    

    self.md_page=wx.Panel(self.pnl,-1,size=(720,400),style=wx.FULL_REPAINT_ON_RESIZE)
   
    self.tench=wx.Panel(self.pnl)
    self.t1=wx.Panel(self.pnl) 
    self.t2=wx.Panel(self.pnl) 
    self.t3=wx.Panel(self.pnl,-1) 

    # ------------------------------------------------------------        
  
    self.mgr = aui.AuiManager()
    self.mgr.SetManagedWindow(self.pnl)        
    
    self.mgr.AddPane(self.md_page, aui.AuiPaneInfo().Top().
                     BestSize(-1,400).MinSize((-1, 400)).
                     CloseButton(False). Name("Notebook"))

    self.mgr.AddPane(self.gridPanel,aui.AuiPaneInfo().Bottom().CenterPane().
                BestSize((500,100)).MinSize((100, -1)).Layer(1).                    
                Caption("wxPython Demo").
                CloseButton(False).Name("DemoTree"))

    self.mgr.AddPane(self.tench,aui.AuiPaneInfo().Right().      
                Layer(0).BestSize((200,100)).                   
                Caption("Demo Log Messages").
                CloseButton(False).Name("LopgWindow"))
    
    self.mgr.AddPane(self.t2,aui.AuiPaneInfo().Right().
                Layer(0).Position(1).
                Caption(" Messages").
                CloseButton(False).Name("LopgWindow333"))  

    self.mgr.AddPane(self.t1, aui.AuiPaneInfo().Right().
                Layer(0).Position(2).            
                Caption(" Messages").
                CloseButton(False).Name("LopgWindow3")) 

    self.mgr.AddPane(self.t3,aui.AuiPaneInfo().Right().
                BestSize(200,830).Layer(2).                    
                Caption("Log Messages").
                CloseButton(False).Name("LopgWindow2"))   
   
    self.mgr.Update()

    self.Bind(wx.EVT_SIZE,self.OnSize)       

def OnSize(self,e):           
  
    print(self.GetClientSize(),self.md_page.GetClientSize(),self.t3.GetClientSize())

    self.mgr.Update()        
    self.Refresh()        
    e.Skip()  

class App(wx.App):
def OnInit(self):
“”“Create the main window and insert the custom frame.”""
frame = CanvasFrame()
self.SetTopWindow(frame)
frame.Show(True)
return True

if name == ‘main’:
app = App()
app.MainLoop()

Hi, angkw567,

Try this:

        def echo(v):
            print("v.EventObject =", v.EventObject)
            print(self.ClientSize,
                  self.md_page.ClientSize)
            v.Skip()
        self.Bind(wx.EVT_SIZE, echo)
        self.md_page.Bind(wx.EVT_SIZE, echo)

On my PC it outputs:

v.EventObject = <__main__.CanvasFrame object at 0x000001C2107AB280>
(934, 311) (0, 0)
v.EventObject = <wx._core.Panel object at 0x000001C2107C5C10>
(934, 311) (726, 290)

At the first SizeEvent from the CanvasFrame you can see that the children have not yet been resized. The following SizeEvent from the child window seems to show the correct size.

PS.
The code you posted has broken formatting. Next time fence your code with three backticks like this:

```python
(code here)
```

otherwise, we have to reformat your code.

      Thank you ! and I have an other question.
    In the above example, I put self Change md to Notebook, that is
             self.nb=wx.Notebook(self.pnl, -1, style=wx.CLIP_CHILDREN)
             self.nb.AddPage(self.md_page, "Text1")

and add other panel
self.nb.AddPage(wx.Panel(self.nb), “Text2”)
At this time, I found that when using the arrow keys on the keyboard, the focus would run to the title of the first page of Notebook, and when I press left and right ,notebook change page.So I found that I could not get the arrow key values(’<’,’>’,’^’) using the keyboard events. I.e
self.Bind(wx.EVT_KEY_UP,self._onKeyDown)
def onKeyDown(self,e):
print(e.GetUnicodeKey())

In general, you can catch arrow key events with EVT_CHAR_HOOK.
Note that for wx.Panel, arrow keys trigger EVT_NAVIGATION_KEY instead of EVT_KEY_DOWN.