当按下Enter键时,我已经成功地从输入字段获取用户输入,并显示在文本小部件上,但是当我尝试使用用户输入的最后一个答案构建嵌套的if/语句时,它似乎无法识别它,并且停止了。你知道吗
root = Tk()
...
Text and Entry widgets created
...
def Enter_pressed(event):
global input_get
input_get = input_field.get()
print(input_get)
messages.tag_config("right", justify="right")
messages.insert(INSERT, '%s\n' % input_get, "right")
input_user.set('')
return "continue"
frame = Frame(root)
input_field.bind("<Return>", Enter_pressed)
frame.pack()
def question():
question1 = str(">>>Do you like apples?")
messages.insert(INSERT, '%s\n' % question1)
if input_get == str("Yes") or input_get == str("yes"):
messages.insert(INSERT, ">>>Great")
else:
question2 = str(">>>How about peaches?")
messages.insert(INSERT, '%s\n' % question2)
if input_get == str("Yes") or input_get == str("yes"):
messages.insert(INSERT, ">>>I like peaches too.")
else:
messages.insert(INSERT, ">>Have you tried mango?")
messages.after(5000, question)
root.mainloop()
我正在努力向一个面向对象的方法传福音。。。看看下面的脚本
感谢您抽出时间回复。我试过你的选择,但不知怎么还是没能成功
我试着在def Enter\pressed(event)代码块中插入嵌套的if语句,它可以工作到一定程度。它识别第一个“如果”和最后一个“其他”,但不识别中间的“如果”和“其他”。你知道吗
在按下Return键作为文本小部件中显示的最后一个问题的答案之后,程序不应该看到并使用每个新的输入吗?你知道吗
相关问题 更多 >
编程相关推荐