from random import randrange
import wx

class Gui(wx.Frame):

    def __init__(self, parent):
        super().__init__(
            parent, title='ScrolledWrapSizer', size=(440, 420))

        self.sb = self.CreateStatusBar(style=wx.STB_SIZEGRIP)

        panel = wx.Panel(self)
        vbox = wx.BoxSizer(wx.VERTICAL)

        scrwin = wx.ScrolledWindow(panel)
        scrwin.ShowScrollbars(
            wx.SHOW_SB_NEVER, wx.SHOW_SB_DEFAULT)
        scrwin.SetScrollRate(20, 20)

        self.insert_items(scrwin)

        vbox.Add(scrwin, 1, wx.EXPAND)
        panel.SetSizer(vbox)

        self.Show()

    def insert_items(self, scrwin):
        self.ctrl_id = {}                                      # ctrl_id: pos, colour
        ws = wx.WrapSizer()
        for idx in range(500):
            btn = wx.Button(
                scrwin, size=(40, 40), style=wx.BORDER_NONE)
            colour = (randrange(255), randrange(255), randrange(255))
            btn.SetBackgroundColour(colour)
            self.ctrl_id[btn.GetId()] = (idx, colour)
            ws.Add(btn, 1, wx.LEFT|wx.BOTTOM|wx.RIGHT|wx.EXPAND, 5)
            btn.Bind(wx.EVT_ENTER_WINDOW, self.set_info)
        scrwin.SetSizer(ws)

    def set_info(self, evt):
        self.sb.SetStatusText(
            ''.join((
                f'Colour {self.ctrl_id[evt.GetId()][0]}  ',
                f'is  RGB{self.ctrl_id[evt.GetId()][1]}')))

if __name__ == "__main__":
    app = wx.App()
    Gui(None)
    app.MainLoop()
