[英]How to make a Label appear then disappear after a certain amount of time in python tkinter
[英]How to make python response after a certain amount of time?
我想让python在10秒后响应一个答案。
我正在执行Python挑战,我必须编写一个程序来询问用户“您的问题是什么?”。 该程序应以“让我考虑一下”作为响应,并暂停10秒钟,然后以“我现在不想回答该问题”进行响应。
然后,程序应向用户询问用户输入的相同问题,然后查看其响应。
这是我到目前为止的内容:
import time
timeout=time.time()+60*10
while True:
answer=str(input('What is your question?'))
print('Let me think about that')
我真的不知道timeout=time.time()+60*10
还是while True
是什么意思,但是当我搜索互联网时,它似乎是正确的。 我现在可以让Python做的就是问一个问题,然后等待输入,然后再次问这个问题,而无需等待。
另一个问题是我将str放在输入之前,我认为这只能输入字母,不能输入数字。 但是当我使用数字作为输入时,Python仍然接受它作为字符串。
您可以使用time.sleep
将python程序暂停n秒:
Help on built-in function sleep in module time:
睡眠(...)睡眠(秒)
Delay execution for a given number of seconds. The argument may be a floating point number for subsecond precision.
因此要暂停10秒钟,只需添加time.sleep(10)
。
如果只想让程序等待十秒钟,请使用time.sleep(10)。 它只会使程序暂停十(或许多)秒,然后继续执行剩余的代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.