Update labels from spinbox value when widgets are created by a for loop
<p>I have add multiple spinboxes and labels in a gui window using a for loop. The for loop creates the spinbox and labels on the same row. Then in the next irritation of the loop creates another row of labels and spinbox. How do I get the value from the spinbox (either when clicked or when incremented or decremented), then do calculation with the value from the clicked spinbox and update a label that is on the same row as the spinbox? </p>

<p>I have added the code I used to create spinboxes using a for loop.</p>

<pre><code>import Tkinter as tk

win = tk.Tk()

val = int()


def exitProgram():
        print("Exit Button pressed")
        win.quit()
        win.destroy()


def createSpinBoxes():

        boxes = []
        lbls = []
        corr = []

        def Correction(event):
                print "you clicked on", event.widget
                w = event.widget
                if isinstance(w, tk.Spinbox):
                        print "what is w??"
                        print w
                        print repr(w)
                        data = float(w.get())
                        data = (data/2)+3
                        print data
                        lbl.configure(text = str(data))

        def TestCorr(data):
                print data


        # Create Spinbox Title label
        lbl = tk.Label(win, text = 'SpBox#',
                       background = "light gray",
                       font = ('Courier' , 10))
        lbl.grid(column = 0, row = 0, sticky = 'we')

        # Create Nominal Value Title label
        lbl = tk.Label(win, text = 'Nom Val',
                       background = "light gray",
                       font = ('Courier' , 10))
        lbl.grid(column = 1, row = 0, sticky = 'w')

        # Create Correction Title label
        lbl = tk.Label(win, text = 'Corr',
                       background = "light gray",
                       font = ('Courier' , 10))
        lbl.grid(column = 2, row = 0, sticky = 'we')

        # Create Value Parameter labels
        valLabels = ['IN VAL ',
                     'OUT VAL',
                     'COR VAL']
        # Nominal values
        valNom = [37.0,    # Value 1
                  64.0,    # Value 2
                  20.0]    # Value 3

        # Nominal value Level Range
        valRange = [33,  # Min Value 1
                   44,  # Max Value 1
                   62,  # Min Value 2
                   68,  # Max Value 2
                   15,  # Min Value 3
                   25]  # Max Value 3


        valRngCnt = 0
        for i in range(0, 3):
                lbl = tk.Label(win,
                               text = valLabels[i],
                               font = ('Courier' , 10),
                               background = "light pink").grid(column = 0, row = i+2, sticky = 'w')
                val = valNom[i]
                SPbox = tk.Spinbox(win,
                                   from_= valRange[valRngCnt],
                                   to = valRange[valRngCnt+1],
                                   font = ('Courier' , 10),
                                   width = 5,
                                   increment=0.1,
                                   textvariable=val,
                                   command=lambda: TestCorr(val))
                SPbox.grid(column = 1, row = i+2, sticky = 'w')
                SPbox.delete(0,"end")
                SPbox.insert(0,valNom[i])

                # Debug lines
                print str(valNom[i]) + " Start Range: " + str(valRange[valRngCnt]) + " End Range: " + str(valRange[valRngCnt+1])
                print valRngCnt

                valRngCnt += 2
                lbl = tk.Label(win,
                               background = "light pink",
                               font = ('Courier' , 10))
                lbl.grid(column = 2, row = i+2, sticky = 'w')
                boxes.append(SPbox)
                lbls.append(lbl)
                corr.append(corr)
                SPbox.bind("&lt;Button-1&gt;", Correction)

                # Debug line
                print boxes


createSpinBoxes()

exitButton  = tk.Button(win,
                        text = "Exit",
                        background = "YELLOW",
                        command = exitProgram)
exitButton.grid(column = 4, row = 7, sticky = 'e')



tk.mainloop()
</code></pre>