使用计时器允许连续的文本输入

时间:2014-08-24 05:25:38

标签: python timer

我是初学python程序员,需要帮助!

我想让用户一遍又一遍地输入单词30秒。很简单,就像这样:

做30秒:

InWord = Entry(exchangep2_page1_canvas, width=21, font=("Helvetica", 30, "bold"), relief=GROOVE, textvariable=GettheWord)

InWord.pack(side='left')
InWord.focus_set()
exchangep2_page1_canvas.create_window(500, 425, window=InWord, anchor = NW)

InWord.bind('<Return>', comp_s)

def comp_s(event):
    winsound.Beep(Freq, Dur)
    print (GettheWord.get())
    InWord.delete(0,END)

此处重复代码的结尾

BUT!我也想每秒显示计时器和倒计时!

你能帮忙吗?非常感谢!

1 个答案:

答案 0 :(得分:0)

试试这个:

import datetime

n = datetime.datetime.now()

while 1:
    # your repeated code here
    a = datetime.datetime.now()
    delta = a - n
    if delta.seconds > 1:
        n = a
        print a
    else:
        continue