本文介绍了如何在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

其他问题几乎相同,但答案是不是我想要的.我希望代码在时间结束时返回一条消息,而无需单击"ENTER".

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".

推荐答案

最简单的方法是使用curses模块.您将要设置nodelay(1),并轮询输入. http://docs.python.org/2/howto/curses.html #user-input

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

这篇关于如何在python中设置弹出时间限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 16:39