num没有总结权利

时间:2014-02-21 01:15:00

标签: python python-3.x tkinter

def one():
    return total.set(total.get() + 1.2)
def two():
    return total.set(total.get() + 2.0)
def three():
    return total.set(total.get() + 1.6)
def four():
    return total.set((total.get() + 2.0)
total = IntVar()
total.set(0)
b1 = Button(app,text = "one ",width = 10,command = one)
b1.pack()
b2 = Button(app,text = "two ",width = 10,command = two)
b2.pack()
b3 = Button(app,text = "three ",width = 10,command = three)
b3.pack()
b4 = Button(app,text = "four ",width = 10,command = four)
b4.pack()

总数与数字总和错误。像总数是2.2,你按b1,它增加到3.2,而不是3.4。我试图在很多地方放一个浮点数(返回之后,在total.get()之前...)但它没有用。我想总计为IntVar()的问题,我不明白这是什么。

1 个答案:

答案 0 :(得分:1)

问题是,当您使用IntVar时,您正在使用DoubleVarIntVar会将值截断为舍入整数。 DoubleVar允许您使用浮点数,就像您在onethree函数中一样。