tags:

views:

16

answers:

1

I have a class with a button, it runs the command automatically when the gui is constructed (which i dont want it to do) but then doesnt work again after. What am I doing wrong? Builtin commands such as endcommand work as they should.

relevant excerpts (ignore the indent problem at the very beginning)

class GuiPart(object):    
def __init__(self, master, queue, endCommand):
    self.queue = queue
    # Set up the GUI
    #tkinter.Button(master, text='Done', command=endCommand).grid(row=6,column=6)

    tkinter.Button(text='Update Variables', command=self.updateValues()).grid(row=3)

    Lp_pacingState = tkinter.Label(text="p_pacingState")
    Lp_pacingState.grid(row=1, column=3)
    Tp_pacingState = tkinter.Label(bg="white", relief="ridge",justify="center",width=9)
    Tp_pacingState.grid(row=1, column=4)
    ....

    self.textBoxes = {"p_pacingState" : Tp_pacingState, "p_pacingMode" : Tp_pacingMode, 
                 "p_hysteresis" : Tp_hysteresis, "p_hysteresisInterval" : Tp_hysteresisInterval,
                 "p_lowrateInterval" : Tp_lowrateInterval, "p_vPaceAmp" : Tp_vPaceAmp,
                 "p_vPaceWidth" : Tp_vPaceWidth, "p_VRP" : Tp_VRP}

#def updateValues(self,input):
def updateValues(self):
    testInput = ["p_pacingState=3", "garbage=poop", "p_VRP=5"]
    for updates in testInput:
        print("zzzz")
        var = updates.split("=")
        try:
            self.textBoxes[var[0]].config(text = var[1])
        except:
            pass

So I get "zzzz" printed 3 times at construction of gui (labels dont update their text though) and the button doesnt work after that. Also if theres a better way to update boxes please tell me. I get input from a stream in no particular order or relevance.

Thanks in advance

+1  A: 

When you do this:

command=self.updateValues()

You are calling the function self.updateValues (because of the ()). The result of that function call is being assigned to the command attribute which is not what you want. You need to remove the () so that the command attribute gets a reference to the method rather than the result of calling the method.

Bryan Oakley