Another way to put a lot of wxPython widgets on a limited display area is to use a scrolled panel like the wx.lib.scrolledpanel.ScrolledPanel() widget ...
# testing wxPython's
# wx.lib.scrolledpanel.ScrolledPanel(parent, id, pos, size, style)
# allows for more space than the parent frame has
import wx
import wx.lib.scrolledpanel as sp
class MyScrolledPanel(wx.lib.scrolledpanel.ScrolledPanel):
def __init__(self, parent):
# make the scrolled panel larger than its parent
wx.lib.scrolledpanel.ScrolledPanel.__init__(self, parent,
wx.ID_ANY, size=(800, 600), style=wx.TAB_TRAVERSAL)
# scroll bars won't appear until required
# default is SetupScrolling(scroll_x=True, scroll_y=True)
self.SetupScrolling()
self.SetBackgroundColour("blue")
# this will take up plenty of space for the test
self.createMultiLabel()
def createMultiLabel(self):
# things to put on the labels
label_string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ->UM'
# wx.GridSizer(rows, cols, vgap, hgap)
gsizer = wx.GridSizer(6, 5, 0, 0)
# create a list of labels
# acccess with self.labels[0], self.labels[1] etc.
self.labels = []
for c in label_string:
self.labels.append(wx.StaticText(self, wx.ID_ANY,
label=c, style=wx.ALIGN_CENTRE|wx.SUNKEN_BORDER))
# iterate through the list of labels and set layout
# also font and colour
font = wx.Font(60, wx.MODERN, wx.NORMAL, wx.BOLD)
for x in self.labels:
x.SetFont(font)
x.SetBackgroundColour("yellow")
gsizer.Add(x, 0, flag=wx.ALL, border=20) # |wx.EXPAND
# set the sizer
self.SetSizer(gsizer)
app = wx.App(0)
# create a frame, no parent, use default ID, set title, size
caption = "Multilabel display in a scrolled panel"
frame = wx.Frame(None, wx.ID_ANY, caption, size=(400, 300))
MyScrolledPanel(frame)
frame.Show(True)
app.MainLoop()