因为var5未定义而出错?但它没有上课就运行良好

时间:2016-08-24 05:41:32

标签: python tkinter

class roger:
    root1 = Tk()
    frame1 = Frame(root1, width=100, height=100)
    frame1.pack(side=TOP)
    label5 = Label(frame1, text="x1=")
    label6 = Label(frame1, text="x2=")
    label7 = Label(frame1, text="x3=")
    label8 = Label(frame1, text="x4=")
    label5.grid(row=0)
    label6.grid(row=1)
    label7.grid(row=2)
    label8.grid(row=3)
    var5 = StringVar()
    var6 = StringVar()
    var7 = StringVar()
    var8 = StringVar()


    textbox1 = Entry(frame1, textvariable=var5, bd=10, width=10, font=30)
    textbox1.grid(row=0, column=1)

    textbox2 = Entry(frame1, textvariable=var6, bd=10, width=10, font=30)
    textbox2.grid(row=1, column=1)

    textbox3 = Entry(frame1, textvariable=var7, bd=10, width=10, font=30)
    textbox3.grid(row=2, column=1)

    textbox4 = Entry(frame1, textvariable=var8, bd=10, width=10, font=30)
    textbox4.grid(row=3, column=1)
    hoo = Entry(frame1, width=20, bd=10)
    hoo.grid(row=5, column=0)

    def inverse():
        a = ([float(var5.get()), float(var6.get())], [float(var7.get()), float(var8.get())])
        ans = inv(a)
        hoo.insert(0, ans)

    def eigen():
        a = ([float(var5.get()), float(var6.get())], [float(var7.get()), float(var8.get())])
        ans = eig(a)
        hoo.insert(0, ans)

    k = Button(frame1, text="inverse", command=inverse)
    k.grid(row=4, column=0)

    l = Button(frame1, text="eigen value ", command=eigen)
    l.grid(row=4, column=1)

    root1.mainloop()

1 个答案:

答案 0 :(得分:0)

使用roger.var5代替var5,因为您已将其定义为类的静态属性。与其他变量类似。