from Tkinter import *
root = Tk()
armor = Label(root, text="Armor:", font=("Helvetica", 12))
armor.grid(row=1, column=0)
armorscale = Scale(root, from_=1337, to=20000, orient=HORIZONTAL, length=500)
armorscale.grid(row=1, column=1)
###
damage = Label(root, text="Base Damage:", font=("Helvetica", 12), justify=LEFT)
damage.grid(row=2, column=0)
damagescale = Scale(root, from_=100, to=2000, orient=HORIZONTAL, length=500)
damagescale.grid(row=2, column=1)
###
armorfloat = float(armorscale.get())
damagefloat = float(damagescale.get())
fReduction = float(armorfloat / (armorfloat + 12 * damagefloat))
sReduction = str(fReduction)
fTaken = damagefloat * (1 - (1* fReduction))
sTaken = str(fTaken)
###
def calc1():
armorfloat = float(armorscale.get())
damagefloat = float(damagescale.get())
fReduction = float(armorfloat / (armorfloat + 12 * damagefloat))
sReduction = str(fReduction)
fTaken = damagefloat * (1 - (1 * fReduction))
sTaken = str(fTaken)
print sReduction
print sTaken
return sReduction
return sTaken
###
reduction = Label(root, text="Reduction %:" + sReduction, font=("Helvetica", 12), justify=LEFT)
reduction.grid(row=3, column=0)
taken = Label(root, text="Damage Taken:" + sTaken, font=("Helvetica", 12), justify=LEFT)
taken.grid(row=4, column=0)
button = Button(root, text="Calculate", command=calc1)
button.grid(row=3, column=1, pady=5, sticky=E)
###
root.mainloop()
这是我第一次尝试编程任何东西,所以我完全是个菜鸟。一切似乎都运行良好,打印的东西只是为了证明这一点。问题是在打开程序并移动滑块或单击计算按钮后,GUI 上的值根本没有更新。