嗨,我很难让字符串变成花车。我试图让我的输入文本将输入转换为浮点数,以便我可以计算 bmi。
from Tkinter import *
import tkMessageBox
class MyApp(object):
def __init__(self):
self.root = Tk()
self.root.wm_title("bmi!")
self.label = Label(self.root, text="Enter your height in box one and weight in box two",
font=('Helvetica', 20))
self.label.pack(padx=20,pady=10)
self.labeltext = StringVar()
self.labeltext.set("Another nice label!")
Label(self.root, textvariable=self.labeltext).pack()
self.entrytext = StringVar()
Entry(self.root, textvariable=self.entrytext).pack()
self.entrytext.trace('w', self.entry_changed)
self.entrytext2 = StringVar()
Entry(self.root, textvariable=self.entrytext2).pack()
self.entrytext2.trace('w', self.entry_changed)
self.root.mainloop()
def entry_changed(self, a, b, c):
s = self.entrytext.get()
b=self.entrytext2.get()
a=getdouble(s)
d=getdouble(b)
c=(a/(d**2))*703
self.labeltext.set(c)
MyApp()