我想有一个时间限制,以便在下面的代码中输入输入。换句话说,应该有一个定时器跟踪时间,如果超过了限制,代码应该自动打印出“游戏结束”这样的消息,而不必按任何键。这是一种弹出式窗口。如何在python中设置弹出时间限制?
def human(player, panel):
print print_panel(panel)
print 'Your Turn! , Hint: "23" means go to row No.2 column No.3/nYou got 1 min to move.'
start_time = time.time()
end_time = start_time + 60
while True :
move = raw_input('> ')
if move and check(int(move), player, panel):
return int(move)
else:
if (time.time() < end_time):
print 'Wrong move >> please try again.'
else:
print "Game over"
return panel, score(BLACK, panel)
break
其他question几乎是相同的,但答案不是我所期待的。我希望代码在没有点击“ENTER”的情况下返回一条消息。
我检查了这个问题及其答案。我使用了建议的答案,但它仍然需要我按下输入以检查时间,如果时间不足,则返回“游戏结束”。这已经应用于代码。我希望代码能够跟踪时间,并在点击Enter之前弹出消息。 – msc87
我想我需要设置一个事件来激发超时,然后处理程序打印正确的消息。信号类只能在Unix中工作。任何建议! – msc87