How to refresh Scrolledwindow after Notebook changed

Hi all,
My GUI uses a Scrolledwindow() and it contains a Notebook in which I will delete old page and replace with new page. Because the new page has more widgets, the scrollwindow needs update its scrollbar to show the new page completely. But only when I maximize or minimize the window, the scrollbar will refresh.I try to use .Refresh() after new page added. It dosen’t seem to work.

Is there some way to update scroll window after notebook changed?I appreciate all feedback.

Thanks
Yuan

Hi yuan948,
You should try SendSizeEvent.
https://wxpython.org/Phoenix/docs/html/wx.Window.html#wx.Window.SendSizeEvent

In the code after you delete the old page and replace it with the new page, try adding a call to the ScrolledWindow’s FitInside() method.

import wx

class MyFrame(wx.Frame):
    def __init__(self, *args, **kwds):
        kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwds)
        self.SetSize((400, 300))
        self.SetTitle("Scrolled Window with Notebook")
        self.panel_1 = wx.Panel(self, wx.ID_ANY)
        sizer_1 = wx.BoxSizer(wx.VERTICAL)
        self.scrolled_window = wx.ScrolledWindow(self.panel_1, wx.ID_ANY, style=wx.TAB_TRAVERSAL)
        self.scrolled_window.SetScrollRate(10, 10)
        sizer_1.Add(self.scrolled_window, 1, wx.EXPAND, 0)
        sizer_2 = wx.BoxSizer(wx.VERTICAL)
        self.notebook = wx.Notebook(self.scrolled_window, wx.ID_ANY)
        sizer_2.Add(self.notebook, 1, wx.EXPAND, 0)
        self.pane_1 = wx.Panel(self.notebook, wx.ID_ANY)
        self.notebook.AddPage(self.pane_1, "Original pane")
        sizer_3 = wx.BoxSizer(wx.HORIZONTAL)

        self.list_ctrl_1 = wx.ListCtrl(self.pane_1, wx.ID_ANY, style=wx.LC_HRULES | wx.LC_REPORT | wx.LC_VRULES)
        self.list_ctrl_1.AppendColumn("A", format=wx.LIST_FORMAT_LEFT, width=-1)
        self.list_ctrl_1.AppendColumn("B", format=wx.LIST_FORMAT_LEFT, width=-1)
        self.list_ctrl_1.AppendColumn("C", format=wx.LIST_FORMAT_LEFT, width=-1)
        sizer_3.Add(self.list_ctrl_1, 1, wx.EXPAND, 0)

        self.change_button = wx.Button(self.panel_1, wx.ID_ANY, "Change Pane")
        sizer_1.Add(self.change_button, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.BOTTOM | wx.TOP, 8)

        self.pane_1.SetSizer(sizer_3)
        self.scrolled_window.SetSizer(sizer_2)
        self.panel_1.SetSizer(sizer_1)
        self.Layout()

        self.Bind(wx.EVT_BUTTON, self.OnChange, self.change_button)


    def OnChange(self, _event):
        pane = wx.Panel(self.notebook, wx.ID_ANY)
        sizer = wx.BoxSizer(wx.VERTICAL)
        for i in range(8):
            b = wx.Button(pane, wx.ID_ANY, str(i+1))
            sizer.Add(b, 0, wx.LEFT | wx.TOP, 2)
        pane.SetSizer(sizer)
        pane.Layout()
        self.notebook.AddPage(pane, "New pane")
        self.notebook.DeletePage(0)
        self.scrolled_window.FitInside()


class MyApp(wx.App):
    def OnInit(self):
        self.frame = MyFrame(None, wx.ID_ANY, "")
        self.SetTopWindow(self.frame)
        self.frame.Show()
        return True

if __name__ == "__main__":
    app = MyApp(0)
    app.MainLoop()

Thanks for all replies! FitInside() worked.Many Thanks