Search code examples
pythonwxpython

Splitter window issue


I am splitting a dialog box into 2 sections and using grid sizer to show list separately in section 1. I also use the length of list to create radiobox to hold three buttons. But with following script I am unable to show scroll bar to see full list of items. Any suggestions to fix it would be appreciative.

import wx
# I have following list available: lut_code

class MyFrame(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, "Modify Hydrologic Condition", wx.DefaultPosition, wx.Size(900, 600))

        splitter = wx.SplitterWindow(self, -1)
        scroll1 = wx.ScrolledWindow(splitter, -1)
        scroll1.SetBackgroundColour(wx.WHITE)
        scroll1.SetVirtualSize(scroll1.GetBestSize() + (250,250))
        scroll1.SetScrollRate(10,10)


        grid_sizer = wx.GridSizer( 0, 8, 0, 0 )

        self.head1 = wx.StaticText(scroll1, wx.ID_ANY, u"Code", (15,5))
        self.head1.Wrap( -1 )
        grid_sizer.Add( self.head1, 0, wx.ALL, 5 )

        v = 0
        for lu in lut_code:
            v += 40
            self.column11 = wx.StaticText(scroll1, wx.ID_ANY, str(lu), (15,v))
            self.column11.Wrap( -1 )
            grid_sizer.Add( self.column11, 0, wx.ALL, 5 )


        rb = 0
        radio1Choices = ['F','G','P']
        for i in range(1,len(lut_code)):
            rb += 40
            self.radio1 = wx.RadioBox(scroll1, wx.ID_ANY, wx.EmptyString, (550,rb), (30,5), radio1Choices, 3, wx.RA_SPECIFY_COLS | wx.NO_BORDER)
            self.radio1.SetSelection( 0 )
            grid_sizer.Add( self.radio1, 0, wx.ALL, 5)

        scroll2 = wx.ScrolledWindow(splitter,-1)
        scroll2.SetBackgroundColour("light-grey")
        message = """Blank"""

        wx.StaticText(scroll2, -1,message, (15,150))
        splitter.SplitVertically(scroll1,scroll2,-220)

    def OnClose(self, event):
        self.Show(False)

class MyApp(wx.App):
    def OnInit(self):
        frame = MyFrame(None, -1, 'splitterwindow.py')
        frame.Show(True)
        self.SetTopWindow(frame)
        return True

app = MyApp(0)
app.MainLoop()

Solution

  • you need to add in your program below scroll2 =wx.ScrolledWindow(splitter,-1)

    scroll1.SetVirtualSize(scroll1.GetBestSize())
    

      import wx
    # I have following list available: lut_code
    
    class MyFrame(wx.Frame):
        def __init__(self, parent, id, title):
            wx.Frame.__init__(self, parent, id, "Modify Hydrologic Condition", wx.DefaultPosition, wx.Size(900, 500))
    
            splitter = wx.SplitterWindow(self, -1)
            scroll1 = wx.ScrolledWindow(splitter, -1)
            scroll1.SetBackgroundColour(wx.WHITE)
            #scroll1.SetVirtualSize(scroll1.GetBestSize() + (250,250))
            scroll1.SetScrollRate(1,1)
    
    
            grid_sizer = wx.GridSizer( 0, 8, 0, 0 )
    
            self.head1 = wx.StaticText(scroll1, wx.ID_ANY, u"Code", (15,5))
            self.head1.Wrap( -1 )
            grid_sizer.Add( self.head1, 0, wx.ALL, 5 )
    
            v = 0
    
            lut_code=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
            for lu in lut_code:
                v += 40
                self.column11 = wx.StaticText(scroll1, wx.ID_ANY, str(lu), (15,v))
                self.column11.Wrap( -1 )
                grid_sizer.Add( self.column11, 0, wx.ALL, 5 )
    
    
            rb = 0
            radio1Choices = ['F','G','P']
            for i in range(0,len(lut_code)):
                rb += 40
                self.radio1 = wx.RadioBox(scroll1, wx.ID_ANY, wx.EmptyString, (550,rb), (30,5), radio1Choices, 3, wx.RA_SPECIFY_COLS | wx.NO_BORDER)
                self.radio1.SetSelection( 0 )
                grid_sizer.Add( self.radio1, 0, wx.ALL, 5)
    
            scroll2 =wx.ScrolledWindow(splitter,-1)
            scroll1.SetVirtualSize(scroll1.GetBestSize())# + (250,250))
            #wx.SetupScrolling(self, scroll_x=True, scroll_y=True, rate_x=20, rate_y=20, scrollToTop=True)
    
    
            scroll2.SetBackgroundColour("light-grey")
            message = """Blank"""
    
            wx.StaticText(scroll2, -1,message, (15,150))
            splitter.SplitVertically(scroll1,scroll2,-220)
    
        def OnClose(self, event):
            self.Show(False)
    
    class MyApp(wx.App):
        def OnInit(self):
            frame = MyFrame(None, -1, 'splitterwindow.py')
            frame.Show(True)
            self.SetTopWindow(frame)
            return True
    
    app = MyApp(0)
    app.MainLoop()
    

    output: enter image description here