I have been trying to use a wxPython textctrl to display a list of files, but it did not fit my purposes. The wx.StaticText seemed useful, and a ll works except for one major kink; I don't know how to scroll it.

Moved post to its own thread, since the sticky is not for questions.

Edited by vegaseat: rules

Attachments smileyanim.gif 5.33 KB
6 Years
Discussion Span
Last Post by mack00234

You can use multiple labels on a scrolled panel. Here is an example ...

# the wx.lib.scrolledpanel.ScrolledPanel() widget scrolls
# multiple labels in the panel

import wx
import wx.lib.scrolledpanel as sp

class MyScrolledPanel(sp.ScrolledPanel):
    def __init__(self, parent):
        # make the scrolled panel larger than its parent
        sp.ScrolledPanel.__init__(self, parent,
            wx.ID_ANY, size=(300, 600), style=wx.TAB_TRAVERSAL)
        # scroll bars won't appear until required
        # default is SetupScrolling(scroll_x=True, scroll_y=True)

        # this will take up plenty of space for the test
        # change the text in the third label from the top
        # index is zero based so the index is 2
        self.labels[2].SetLabel("changed the third label!!!")

    def createMultiLabels(self):
        # things to put on the labels
        label_str = """
        This is just a long text to check on scrolling ----- 
        """ * 3

        # wx.GridSizer(rows, cols, vgap, hgap)
        gsizer = wx.GridSizer(25, 1, 0, 0)

        # create a list of labels
        # acccess with self.labels[0], self.labels[1] etc.
        self.labels = []
        for word in label_str.split():
            self.labels.append(wx.StaticText(self, wx.ID_ANY,

        # iterate through the list of labels and set layout
        for x in self.labels:
            gsizer.Add(x, 0, flag=wx.ALL, border=0)

        # set the sizer

app = wx.App(0)
# create a frame, no parent, use default ID, set title, size
caption = "Multilabels in a scrolled panel"
frame = wx.Frame(None, wx.ID_ANY, caption, size=(300, 200))

Thank you vegaseat. The code above will definitely help me in the future, but I have discovered that the wx.ListBox fits my program better(I need to be able to select files and remove them from a list).

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.