I am trying to add a custom widget dynamically, multiple times. However, the widgets just stack up in the same place.

I have tried several combinations of Layout() and Fit() and setSizerAndFit() after adding custom widget to the sizer

Thank you for any help

#!/usr/bin/env python
# -*- coding: US-ASCII -*-
#
# generated by wxGlade 0.6.8
#

import wx

# begin wxGlade: dependencies
import gettext
# end wxGlade

# begin wxGlade: extracode
# end wxGlade

class WordGroup(wx.Panel):
    def __init__(self, parent, id):
        wx.Panel.__init__(self, parent, id)
        self.parent = parent
        self.text_ctrl_1 = wx.TextCtrl(parent, wx.ID_ANY, "", style=wx.TE_MULTILINE | wx.TE_NO_VSCROLL)
        self.label_1 = wx.StaticText(parent, wx.ID_ANY, _(""))
        self.slider_1 = wx.Slider(parent, wx.ID_ANY, 0, 1, 10, style=wx.SL_VERTICAL | wx.SL_LABELS)

        grid_sizer_1 = wx.FlexGridSizer(1, 2, 1, 0)
        sizer_2 = wx.FlexGridSizer(2, 1, 0, 0)
        grid_sizer_1.Add(self.text_ctrl_1, 0, wx.EXPAND, 0)
        sizer_2.Add(self.label_1, 0, 0, 0)
        sizer_2.Add(self.slider_1, 0, wx.EXPAND, 0)
        grid_sizer_1.Add(sizer_2, 1, wx.EXPAND, 0)
        self.SetSizer(grid_sizer_1)
        grid_sizer_1.AddGrowableRow(0)
        grid_sizer_1.AddGrowableCol(0)

class MyFrame1(wx.Frame):
    def __init__(self, *args, **kwds):
        # begin wxGlade: MyFrame1.__init__
        kwds["style"] = wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwds)
        self.newWordGroup = WordGroup(self, wx.ID_ANY)
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.__set_properties()
        self.__do_layout()
        # end wxGlade

    def __set_properties(self):
        # begin wxGlade: MyFrame1.__set_properties
        self.SetTitle(_("frame_2"))
        # end wxGlade

    def __do_layout(self):
        # begin wxGlade: MyFrame1.__do_layout
        # sizer_1 = wx.BoxSizer(wx.VERTICAL)

        self.sizer.Add(self.newWordGroup, 1, wx.EXPAND, 0)
        self.SetSizer(self.sizer)
        self.sizer.Fit(self)
        self.Layout()
        # end wxGlade

    def addWordGroups(self):
        for i in xrange(5):
            self.sizer.Add(WordGroup(self, wx.ID_ANY))
            #self.sizer.Layout()
            self.Fit()
# end of class MyFrame1
class Text(wx.App):
    def OnInit(self):
        wx.InitAllImageHandlers()
        frame_2 = MyFrame1(None, wx.ID_ANY, "")
        self.SetTopWindow(frame_2)
        frame_2.Show()
        frame_2.addWordGroups()
        return 1

# end of class WordGroup

if __name__ == "__main__":
    gettext.install("app") # replace with the appropriate catalog name

    app = Text(0)
    app.MainLoop()

parent in custom widget should be set to its own panel, not passed in parent

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.