[英]How do you continue a while loop only if a function has been called?
我正在编写一个生成单词的 Gui 游戏,然后用户可以输入答案。 我现在需要一个循环来防止这些单词弹出,以便仅在检查单词是否正确时才运行。
# Functions
def words():
global score
global timer
start = time.time()
while time.time() - start <= 60:
entry.focus_set() # Activate the entry box
word = random.choice(word_list[0])
word_label.config(text=word)
# Here should be code that makes it that a new word is only generated if the check word is run
root.update()
results(score)
def check_word(event, word, score):
global wrong
if entry.get().lower() == word.lower():
score += 1
entry.delete(0, 9999999)
else:
wrong += 1
参考here ,我认为您可以将一个键事件绑定到将调用2个方法的输入框:
root.update()
results(score)
就像是:
from Tkinter import *
root = Tk()
def key(event):
print "pressed", repr(event.char)
root.update()
results(score)
frame = Frame(root, width=100, height=100)
frame.bind("<Key>", key)
frame.pack()
root.mainloop()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.