-1
我正在制作一个BMI计算器只是为了让我的脑袋绕过tkinter。我被困在这一部分 - 我该如何做到这一点,所以它从入口小部件获得浮点数?Tkinter条目插件浮点数
这里是我的代码
获得进入输入一些片段(这是在一个叫做calculateBMI功能)
hgtval = float(height.get())
wgtval = float(weight.get())
下面是创建变量,使输入框中。
hgt = StringVar()
wgt = StringVar()
height = Entry(root, stringvariable=hgt).grid(row=1, column=2)
weight = Entry(root, stringvariable=wgt).grid(row=2, column=2)
运行整个节目我给出这个错误:
C:\Python34\python.exe I:/programming/project/bmi.py
Traceback (most recent call last):
File "I:/programming/project/bmi.py", line 35, in <module>
height = Entry(root, stringvariable=hgt).grid(row=1, column=2)
File "C:\Python34\lib\tkinter\__init__.py", line 2478, in __init__
Widget.__init__(self, master, 'entry', cnf, kw)
File "C:\Python34\lib\tkinter\__init__.py", line 2086, in __init__
(widgetName, self._w) + extra + self._options(cnf))
_tkinter.TclError: unknown option "-stringvariable"
这应该是'textvariable'不'stringvariable'。See [here](http://effbot.org/tkinterbook/entry.htm)。 –
http://effbot.org/tkinterbook/entry.htm –