【发布时间】:2014-05-12 20:55:03
【问题描述】:
我正在尝试制作一个基本的面积计算器来做这个 base*height=area
到目前为止我的代码是这样的(至少是你需要看到的部分)
#Labels and Boxes
def calculate():
boxBase*boxHeight
buttonCalculate = Button(text = "Calculate area...", command = calculate)
buttonCalculate.grid(row =4, column =0)
myLabel3=Label(text="Area", fg="black")
myLabel3.grid(row =3, column =0, sticky='w')
boxSolution= Entry()
boxSolution.grid(row =3, column =1)
myLabel2=Label(text="Base", fg="black")
myLabel2.grid(row =0, column =0, sticky='w')
boxBase= Entry()
boxBase.grid(row =0, column =1)
myLabel=Label(text="Height", fg="black",)
myLabel.grid(row =1, column =0, sticky = "w")
boxHeight= Entry()
boxHeight.grid(row =1, column =1)
我想让boxBase 乘以boxHeight 并在按下buttonCalculate 时打印到boxSolution 我该怎么做?
【问题讨论】:
-
boxBase和boxHeight是小部件的实例。使用.get()方法返回它们的值。 effbot.org/tkinterbook/entry.htm#Tkinter.Entry.get-method -
嗯,每当我尝试使用 .get() 时,例如我的 boxBase,它说“boxBase”未定义?有什么想法吗?
-
发布你的代码和完整的错误,我会告诉你,否则可能是很多事情。
标签: python user-interface tkinter python-idle