回车在空闲状态下不起作用? [英] Carriage Return not working in IDLE?

查看:59
本文介绍了回车在空闲状态下不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为保持原位的倒数计时器创建代码:以便每一行覆盖前一行.这是我目前所拥有的:

I'm trying to create a code for a countdown timer that stays in place: so that each line overwrites the previous one. This is what I have so far:

import time

def countdown(t):
    while t:
        mins, secs = divmod(t, 60)
        timeformat = "{:02d}:{:02d}".format(mins, secs)
        print(timeformat, end='\r')
        time.sleep(1)
        t -= 1
    print("That's the end! You lose...\n\n\n\n\n")
    exit()

countdown(10)

然而,输出是:

00:10
00:09
00:08
...
00:00
That's the end! You lose...

为什么回车似乎不起作用?

Why is the carriage return seemingly not working?

推荐答案

IDLE 不支持大多数控制字符,例如如\r\b.它在 2020 年仍然是 true(Python 3.9 不支持)

\r 应该可以工作.

这篇关于回车在空闲状态下不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆