Tkinter label textvariable not changing

≡放荡痞女 提交于 2019-12-02 16:23:34

问题


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.



来源:https://stackoverflow.com/questions/46981834/tkinter-label-textvariable-not-changing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!