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