【发布时间】:2018-07-17 10:45:55
【问题描述】:
这里是代码
from tkinter import*
def final_calculation():
entryField.delete(0,'end')
Wood = entryWood.get()
Steal = entrySteal.get()
output_wood = (Wood *wood_c02)
output_steal = (Steal * steal_c02 )
final = (output_steal + output_wood *c02_coal)
entry.set(final)
steal_c02 = int (5.5)
wood_c02 = int (1.2)
c02_coal = int (0.94)
root = Tk()
root.configure(background="black")
root.title("C02 caculator")
root.resizable(1,0)
root.columnconfigure(0,weight=1)
root.columnconfigure(1,weight=1)
entry = StringVar()
entryField = Entry(root, textvariable=entry,background="white",foreground="black",justify=CENTER)
entryField.grid(row=0,column=0,columnspan=2,sticky=W+E)
entryField.columnconfigure(0,weight=1)
labelWood = Label(root, text="Amount of wood",background="black",foreground="grey90")
labelWood.grid(row=1,column=0, sticky=E)
labelSteal = Label(root, text="Amount of steal",background="black",foreground="grey90")
labelSteal.grid(row=2,column=0, sticky=E)
entryWood = Entry(root,background="grey80",foreground="black")
entryWood.grid(row=1,column=1,sticky=W)
entrySteal = Entry(root,background="grey80",foreground="black")
entrySteal.grid(row=2,column=1,sticky=W)
button = Button(root, text="caculate C02", command= final_calculation)
button.grid(row=3, columnspan=2)
root.mainloop()
按运行,一切都很好。在您计算出问题中重新解决的总和之前,即第二个输入重复 5 次并显示为输出,任何帮助都会很有帮助。
亲切的问候:49.95
【问题讨论】:
-
您的变量是字符串,而不是整数。你必须转换它们:
Wood = int(entryWood.get()) .... -
谢谢你解决了部分问题,但它仍然只是 * 5 的第二个数字
-
int(5.5) => 5. 你可能想要 float() 在这里。
标签: python tkinter error-handling