ValueError:无法将字符串转换为float,尽管值已经是int而不是字符串

时间:2017-03-27 03:16:55

标签: python tkinter

我已经设置了一个带有条目小部件的GUI。

def gui_function():
value = v.get()
if value == 2:
    print 'Converting from decimal to binary...'
    foundvalu = float(dec_entry_a.get())

    new_num_input = int(foundvalu)

    result = Decimal_to_Binary.convert2(new_num_input)

    bin_out_b.config(state=NORMAL)
    bin_out_b.delete(0, END)
    bin_out_b.insert(0, result)"

当我运行GUI并在条目小部件中输入37时,我收到以下错误:

Exception in Tkinter callback
Converting from decimal to binary...
Traceback (most recent call last):
  File "C:\Python27\lib\lib-tk\Tkinter.py", line 1537, in __call__
    return self.func(*args)
  File "C:/Users/DeclanTK/Documents/School/Drexel/Winter Term Sophomore/ECEC 301 (Advanced Programming)/Project/Egg Project/Binary Converter egg/BtoDConverter-0.1/My_Files/Number_Converter_GUI.py", line 38, in gui_function
    foundvalu = float(dec_entry_a.get())
ValueError: could not convert string to float: 

Process finished with exit code 0

我可以提供更多代码,但我根本无法理解为什么它不接受37并将其转换为浮动。

0 个答案:

没有答案