0

In this question I got help with the wxPython ScrolledPanel panel, which really helped, but I have noticed that the scrollbar is interfering/overlapping with the buttons I am creating. Is there a way to get this to stop?

Code:

class ScrollyPanel(wxScrolledPanel.ScrolledPanel):
    def __init__(self, parent):
        wxScrolledPanel.ScrolledPanel.__init__(self, parent, style=wx.VSCROLL,
            size=(200,200))
        self.__sizer = wx.WrapSizer()
        self.SetupScrolling(scroll_x = False, scroll_y = True)

        self.addButton(200)
        self.SetSizer(self.__sizer)
        self.Bind(wx.EVT_SIZE, self.onSize)

        self.SetAutoLayout(True)
        self.Layout()

    def addButton(self, num):
        size = wx.Size(200, 100)

        for i in range(1, num):
            btn = wx.Button(self, wx.ID_ANY, "btn"+str(i), size = size,
                style = wx.BORDER_SIMPLE)
            self.__sizer.Add(btn, 0, wx.ALL, 2)

    def onSize(self, evt):
        size = self.GetSize()
        vsize = self.GetVirtualSize()
        self.SetVirtualSize((size[0], vsize[1]))

        evt.Skip()

Issue I am seeing: enter image description here

Is there a way to add padding so the scrollbars aren't overlapping the buttons?

Thank you

xxx

Swatcat
  • 73
  • 6
  • 21
  • 57
  • why do you need to use WrapSizer? Try wx.FlexGridSizer one. You can choose the number of column/rows and also the padding between rows/columns. – Igor Dec 06 '17 at 19:32
  • how do I make it expand if the window is expanded then please? – Swatcat Dec 06 '17 at 20:38
  • you don't need to - it is sizer responsibility. – Igor Dec 06 '17 at 22:25
  • Sorry I don't get it... self.__sizer = wx.FlexGridSizer() are buttons on a single row (going off the screen). – Swatcat Dec 06 '17 at 23:38
  • check the documentation. You can set number of rows and number of columns in the constructor. And then use "AddGrowableRow()/Column()" in the code. – Igor Dec 07 '17 at 15:34

0 Answers0