在这个程序中,我创建了三个条目小部件,我可以在其中放置任何值并通过等式1st_entrybox - 2nd_entrybox + 3rd_entrybox连接它们。单击“总计”按钮后,我应该在名为“能量跨度”的框中得到总答案(该名称与我的项目相关)。但我没有得到答案。你能帮忙吗?
提前致谢。
以下是我的代码:
from __future__ import division
from Tkinter import *
root = Tk()
btn1=Frame(root, width=600, height=600, bd=16, relief="raise")
btn1.pack(side=LEFT)
btn2=Frame(root, width=600, height=600, bd=16, relief="raise")
btn2.pack(side=LEFT)
def Sum():
if var.get == 1:
Qty1 = float(Trn.get())
Qty2 = float(Intr.get())
Qty3 = float(delG.get())
Sumup = Qty1 - Qty2 + Qty3
Total.set(Sumup)
def Reset():
Trn.set("0")
Intr.set("0")
delG.set("0")
Total.set("0")
var = IntVar()
Trn = IntVar()
Intr = IntVar()
delG = IntVar()
Total = IntVar()
rb1 = Radiobutton(btn1, variable=var, value=1,
font=('Helvetica',22,'bold')).grid(row=0, column=0, sticky=W)
lbl = Label(btn1, font=('Helvetica',22,'bold'), text="TS",
fg="black").grid(row=1, column=0)
ent = Entry(btn1, font=('Helvetica', 22, 'bold'), bd=4, width=13, bg=
"white",textvariable=Trn).grid(row=1, column=1)
lbl1 = Label(btn1, font=('Helvetica',22,'bold'), text="INT", fg="black",
bd=16).grid(row=2, column=0)
ent1 = Entry(btn1, font=('Helvetica', 22, 'bold'), bd=4, width=13, bg=
"white",textvariable=Intr).grid(row=2, column=1)
lbl2 = Label(btn1, font=('Helvetica',22,'bold'), text="Delta G", fg="black",
bd=16).grid(row=3, column=0, sticky=W)
ent2 = Entry(btn1, font=('Helvetica', 22, 'bold'), bd=4, width=13, bg= "white",
textvariable=delG).grid(row=3, column=1)
lblTotal = Label(btn1, font=('Helvetica', 22, 'bold'),text = "Energy Span",
fg="black", bd=16, justify="left")
lblTotal.grid(row=4, column=0)
lblans = Entry(btn1, font=('Helvetica',22,'bold'), bd=4, width=12,
bg="white", textvariable=Total, relief= "sunken").grid(row=5,column=1)
btnTotal = Button(btn2,pady=8, bd=8, fg="black", font=('Helvetica', 25,
'bold'), width=16,height=2,text = "Total", bg="white",
command=Sum).grid(row=1, column=0)
btnReset = Button(btn2,pady=8, bd=8, fg="black", font=('Helvetica', 25,
'bold'), width=16,height=2,text = "Reset", bg="white",
command=Reset).grid(row=2, column=0)
root.mainloop()
输出图像:Simple calculation
答案 0 :(得分:1)
您忘记拨打.get
,因为您没有将括号括起来。您需要更改
var.get == 1
到
var.get() == 1