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()
这是我第一次尝试编程任何东西,所以我是一个总noob。一切似乎都很好,印刷的东西只是为了证明它。问题在于,打开程序并移动滑块或单击计算按钮后,GUI上的值完全没有更新。图形用户界面不文本
相关,如果不是完整答案:[事件和绑定](http://www.pythonware.com/library/tkinter/introduction/events-and-bindings.htm) – Bakuriu 2013-04-11 11:26:27
您应该修复缩进......尤其是,有2个返回语句没有意义,没有第二个块 – berdario 2013-04-11 11:28:15
我为你修复了它 – berdario 2013-04-11 12:21:54