Tkinter label textvariable not changing

2020-05-08 18:30发布

问题:

I read 4 entry boxes and store them as 4 elements of a matrix (numpy), then when a button is clicked, a function (convert) runs and a matrix is stored in z (z is declared as global in the function (convert)). 4 labels with attribute textvariable assigned a different elemet of z for each label. When it runs, the labels should be the calculated z but instead they're just zeros. When I type z in the command line after I close the program, it prints the correct z.

Sorry if this sounds novice, I come from a C background and I started using python recently.

def convert():
    y[0,0] = float(inA.get()) #previously declared as numpy matrix
    y[0,1] = float(inB.get())
    y[1,0] = float(inC.get())
    y[1,1] = float(inD.get())
    inType = intype.get()
    outType = outtype.get()
    global z
    z = convertParam(outType,convertParam(inType,y,0),1)

outparam11 = tkinter.Label(top,width=5,textvariable = z[0,0]) #label

回答1:

You can't use a normal variable as a textvariable. It must be an instance of one of the special tkinter variables (eg: StringVar). To cause the label to update you could then call the set method of that variable.