python怎样弹出日历_如何在python中设置弹出时间限制?

I want to have a time limit in order to enter the input in the following code. In other words, there should be a timer tracking the time and if it exceeds the limit, the code should print out a message like "Game over" automatically without hitting any key. it is a sort of pop-up.

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

the other question is almost the same but the answer is not what I am looking for. I want the code to return a message when the time is over without hitting "ENTER".

解决方案

The simplest way is to use the curses module. You'll want to set nodelay(1), and poll for input. http://docs.python.org/2/howto/curses.html#user-input

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值