因此,我在tkinter的“输入”框中遇到了麻烦。每当我按下“提交”按钮时,文本输入框中的字符串就会删除。我非常相信这是我的输出问题的根源。
以下代码显示了已定义和使用的输入框(格式可能与实际代码略有出入):
def var_use():
Label (window, text="Metric or Imperial Unit?:", bg="white", fg="black", font="none 12 bold") .grid(row=9, column=10, sticky=W)
textbox_measurement = Entry(window, width=20, bg="white", fg="black")
textbox_measurement.grid(row=10, column=10, sticky=W)
Label (window, text="Please enter your weight here:", bg="white", fg="black", font="none 12 bold") .grid(row=11, column=10, sticky=W)
textbox_weight = Entry(window, width=20, bg="white", fg="black")
textbox_weight.grid(row=12, column=10, sticky=W)
Label (window, text="Please as well, enter your height:", bg="white", fg="black", font="none 12 bold") .grid(row=13, column=10, sticky=W)
textbox_height = Entry(window, width=20, bg="white", fg="black")
textbox_height.grid(row=14, column=10, sticky=W)
return textbox_measurement
return textbox_weight
return textbox_height #so i can call variables from this function
var_use()
我接下来的几行显示了提交按钮的一部分:
def click_submit():
BMI_Calc()
BMI_output = BMI_Calc()
output.delete(0.0, END)
output.insert(END, str(BMI_output))
BMI_Calc我已经测试过,并且我知道它可以工作。我需要获取BMI_output,但是我不能,这是因为要删除文本输入框中的文本。