附上代码:
报错:
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