如何使while循环继续前进,同时仍然在Python中查找输入

时间:2015-10-15 10:31:26

标签: python while-loop user-input

我正在使用Python制作一个像Cookie游戏的Cookie点击器,我正在尝试让while循环继续运行,以便检查是否已经消失(因此它添加了“cookies”),同时仍然在查看用户是否正在制作输入(点击“Cookie”)。

每当我尝试这个时,它会等待输入而不是循环的其余部分。

这就是我目前的代码(当然还有更多):

While True:
    console.clear()
    cookieText = "You have " + str(cookies) + " cookies"
    print cookieText
    clicker = raw_input("")
    if clicker == "":
        cookies += clickerPower
    more...

这是我要添加的内容:

While True:
    last = time()
    if last == timer:
        timer = last
        more...

2 个答案:

答案 0 :(得分:0)

这对我有用(source

import msvcrt

num = 0
done = False
while not done:
    print num
    num += 1

    if msvcrt.kbhit():
        print msvcrt.getch()
        done = True

答案 1 :(得分:0)

答案是threading。但这并不简单。