By using the accepted solution from ScrolledPanel with vertical scrollbar only and WrapSizer, here is a way of putting some custom MyControl
into WrapSizer
with a vertical scrollbar :
Unfortunately, the items that are not drawn at startup won't draw later, even after moving the scrollbar. Here only the first 9 buttons (among 20) are drawn :
import wx
import wx.lib.scrolledpanel as scrolled
class MyControl(wx.PyControl):
def __init__(self, parent, i):
wx.PyControl.__init__(self, parent, wx.ID_ANY, wx.DefaultPosition, size=(100,100))
wx.Button(self, wx.ID_ANY, "btn %d" % i, (0,0), (50,50), 0)
# some other things here
class MyPanel(scrolled.ScrolledPanel):
def __init__(self, parent):
scrolled.ScrolledPanel.__init__(self, parent, style=wx.VSCROLL)
self.sizer = wx.WrapSizer()
self.SetupScrolling(scroll_x = False)
for i in range(1, 20):
btn = MyControl(self, i)
self.sizer.Add(btn, 0, wx.ALL, 10)
self.SetSizer(self.sizer)
self.Bind(wx.EVT_SIZE, self.onSize)
def onSize(self, evt):
size = self.GetSize()
vsize = self.GetVirtualSize()
self.SetVirtualSize((size[0], vsize[1]))
app = wx.App(redirect=False)
frame = wx.Frame(None, size=(400,400))
MyPanel(frame)
frame.Show()
app.MainLoop()
How to correctly draw all the items in such a WrapSizer
?