【发布时间】:2021-11-07 00:52:45
【问题描述】:
我想要 tkinter 中的 Text 标签来不断检查它是否有价值。我希望它处于一个while循环中并在值匹配时退出它。 我的代码不起作用。
while user_input != str(ans):
master = Tk()
master.title("Math")
master.geometry('400x400')
eq = generate_equation(stage=current_stage)
ans = calc(eq)
Label(master=master,text=f"score: {score}").grid(row=0,column=2,sticky=W)
Label(master=master, text=f"{q_num}: {eq}").grid(row=0,column=0 ,sticky=W)
inputtxt = tkinter.Text(master=master,height = 5, width = 20)
inputtxt.grid()
user_input =str(inputtxt.get(1.0,"end-1c"))
mainloop()
【问题讨论】:
-
为什么不绑定到
"<KeyRelease>"?另外你不应该使用while循环母鸡使用tkinter,除非你知道它会导致什么。