Python 如何将tkinter标签小部件中的数据转换为预测函数的浮点值

Python 如何将tkinter标签小部件中的数据转换为预测函数的浮点值,python,machine-learning,tkinter,data-mining,Python,Machine Learning,Tkinter,Data Mining,我试图预测用户给出的一组值 ty = [fst.get(), snd.get(), trdget(), fth.get(), ffth.get(), sxth.get(), svth.get(), eth.get()] yow=rfcmodel.predict(ty) print(yow) ty是变量列表,其中变量为: fst = Entry(root, width=50, borderwidth=5) snd = Entry(root, width=50, borderwidth=5) tr

我试图预测用户给出的一组值

ty = [fst.get(), snd.get(), trdget(), fth.get(), ffth.get(), sxth.get(), svth.get(), eth.get()]
yow=rfcmodel.predict(ty)
print(yow)
ty是变量列表,其中变量为:

fst = Entry(root, width=50, borderwidth=5)
snd = Entry(root, width=50, borderwidth=5)
trd = Entry(root, width=50, borderwidth=5)
fth = Entry(root, width=50, borderwidth=5)
ffth = Entry(root, width=50, borderwidth=5)
sxth = Entry(root, width=50, borderwidth=5)
svth = Entry(root, width=50, borderwidth=5)
eth = Entry(root, width=50, borderwidth=5)
它给了我一个错误值:无法将字符串转换为浮点:

我错过什么了吗

完全回溯错误:

Traceback (most recent call last):
  File "C:/Users/Zayn Justin/PycharmProjects/Software Engineering/Expert System with GUI.py", line 140, in <module>
    ty = [[float(fst.get()),  float(snd.get()), float(trd.get()), float(fth.get()), float(ffth.get()), float(sxth.get()), float(svth.get()), float(eth.get())]]
ValueError: could not convert string to float: 
它仍然给我

Traceback (most recent call last):
  File "C:/Users/Zayn Justin/PycharmProjects/Software Engineering/Expert System with GUI.py", line 39, in <module>
    fstb = float(fst.get())
ValueError: could not convert string to float:
回溯(最近一次呼叫最后一次):
文件“C:/Users/Zayn Justin/PycharmProjects/Software Engineering/Expert System with GUI.py”,第39行,在
fstb=float(fst.get())
ValueError:无法将字符串转换为浮点:

您是否使用变量存储用户输入的数据

例如

他们把它用在名单上


希望它能工作…

您正在传递空值

我建议试试这个

for x in root.winfo_children():
    if x.winfo_class() == 'Entry':
        if x.get() != '':
            # push all to the array
            print(float(x.get()))
            ty.append(float(x.get()))
-伊莱


编辑:也可以先尝试打印值。添加了打印语句

您好,谢谢您的输入,但不幸的是,它没有解决我的问题。我真的很欣赏这个评论。我希望我的模型通过使用用户提供的输入数据来预测一些东西,这些数据来自这个fst=Entry(root,width=50,borderwidth=5)snd=Entry(root,width=50,borderwidth=5)trd=Entry(root,width=50,borderwidth=5)fth=Entry(root,width=50,borderwidth=5)ffth=Entry(root,width=50,borderwidth=5)sxth=Entry(root,width=50,borderwidth=5)svth=Entry(root,width=50,borderwidth=5)eth=Entry(root,width=50,borderwidth=5)但是,它不会接受输入的数据并给出上面的错误。您应该发布完整的错误回溯。这些条目中很可能有空字符串。在将它们传递给predict函数之前,请尝试打印这些条目的值。您什么时候执行所有这些
.get()
调用?我经常看到人们在创建条目后的下一行代码中这样做-这样,在用户有机会看到条目之前,代码就执行了,当然没有时间在条目中实际键入任何内容。谢谢!我终于得到了它!
fst_val = fst.get()
for x in root.winfo_children():
    if x.winfo_class() == 'Entry':
        if x.get() != '':
            # push all to the array
            print(float(x.get()))
            ty.append(float(x.get()))