Populate wx.StaticText controls with dictionary key:value pairs
Question: I have a wxPython GUI application that contains 13 pairs of StaticText
controls that I would like to be able to set labels for problematically.

In terms of regression analysis, each pair of StaticText controls represents
an independent variable and its coefficient. These key:value pairs are
currently stored in a python dictionary, allowing me to use dictionary
comprehension for much of my work.

Right now, I am struggling to display the contents of my python dictionary
inside of my GUI. Any thoughts?

I am happy concatenating the key:value pair inside 1 StaticText control label,
as I think it would be less messy.


Answer: I'm sure there are lots of different ways to do this. I would probably use a
ListCtrl or better yet, ObjectListView. But I went ahead and created an
example using StaticText controls:

    
    
    import wx
    
    ########################################################################
    class MyPanel(wx.Panel):
        """"""
    
        #----------------------------------------------------------------------
        def __init__(self, parent):
            """Constructor"""
            wx.Panel.__init__(self, parent)
    
            self.mainSizer = wx.BoxSizer(wx.VERTICAL)
            self.createControls()
            self.SetSizer(self.mainSizer)
    
        #----------------------------------------------------------------------
        def createControls(self):
            """"""
            myDict = {"var1":"co-eff1", "var2":"co-eff2",
                      "var3":"co-eff3", "var4":"co-eff4",
                      "var5":"co-eff5", "var6":"co-eff6",
                      "var7":"co-eff7", "var8":"co-eff8",
                      "var9":"co-eff9", "var10":"co-eff10",
                      "var11":"co-eff11", "var12":"co-eff12",
                      "var13":"co-eff13"}
            for key in myDict:
                lblOne = wx.StaticText(self, label=key)
                lblTwo = wx.StaticText(self, label=myDict[key])
    
                sizer = wx.BoxSizer(wx.HORIZONTAL)
                sizer.Add(lblOne, 0, wx.ALL, 5)
                sizer.Add(lblTwo, 0, wx.ALL, 5)
                self.mainSizer.Add(sizer)
    
    ########################################################################
    class MyFrame(wx.Frame):
        """"""
    
        #----------------------------------------------------------------------
        def __init__(self):
            """Constructor"""
            wx.Frame.__init__(self, None, title="Frame Example",
                              size=(400,400))
            panel = MyPanel(self)
            self.Show()
    
    if __name__ == "__main__":
        app = wx.App(False)
        frame = MyFrame()
        app.MainLoop()
    

If you want to see what a ListCtrl looks like, go and download the wxPython
demo package and look up the ListCtrl demo. For ObjectListView, you can read
my [tutorial](http://www.blog.pythonlibrary.org/2009/12/23/wxpython-using-
objectlistview-instead-of-a-listctrl/).

