tkinter下不能将输入框转换成float

附上代码:

报错:
m = float(format(inp1.get()))

ValueError: could not convert string to float:

报错是奇怪的,找不到问题……

from tkinter import *
import random
def run1():
    
    t = float(format(inp3.get()))
    global save
    if t>save:
        txt.insert(END, "big")
    else:
        txt.insert(END, "small")
        
def ur():
    
    m = float(format(inp1.get()))
    n = float(format(inp2.get()))
    a=random.randint(m,n+1)
    global save
    save=a
            
root = Tk()
root.geometry('460x240')
root.title('猜数')


lb1 = Label(root, text='开始')
lb1.place(relx=0.1, rely=0.1, relwidth=0.3, relheight=0.1)
lb2 = Label(root, text='结束')
lb2.place(relx=0.6, rely=0.1, relwidth=0.3, relheight=0.1)
lb3 = Label(root, text='猜数')
lb3.place(relx=0.3, rely=0.3, relwidth=0.4, relheight=0.1)
inp1 = Entry(root)
inp1.place(relx=0.1, rely=0.2, relwidth=0.3, relheight=0.1)
inp2 = Entry(root)
inp2.place(relx=0.6, rely=0.2, relwidth=0.3, relheight=0.1)
inp3 = Entry(root)
inp3.place(relx=0.3, rely=0.4, relwidth=0.4, relheight=0.1)
# 方法-直接调用 run1()
ur()
btn1 = Button(root, text='验证', command=lambda: run1())
btn1.place(relx=0.1, rely=0.4, relwidth=0.3, relheight=0.1)
txt = Text(root)
txt.place(rely=0.6, relheight=0.4)
root.mainloop()


环境是anaconda下环境集成的python3.7

因为你程序开始的时候走到 ur() 这一步,会调用 m = float(format(inp1.get())),但是此时 inp1.get() 为空,因此 float('') 也就行不通,自然报错了

你应该是这样想的:
输入两个数字,随机生成一个 key值,然后,输入不同的数值来猜中这个key值。
但是你忽略了一点,就是启动的时候,那两个值你还没输入呢,这个key值怎么会生成呢?

解决方法:
添加一个按钮,触发ur方法,用于生成key值,然后再继续猜值