首页 > 解决方案 > 带有里程碑的 Python 加载栏

问题描述

我试图用可视化制作一个地下控制程序(当然是为了好玩;D)。我知道有许多不同的加载栏库,但是如果您知道我的意思,我找不到任何具有里程碑意义的东西。我在 Windows 上使用 Python 3。我会感谢任何帮助

标签: pythonloading

解决方案


使用 sys 可以实现带有里程碑的加载栏:

def updt(total, progress):
    barLength, status = 25, ""
    progress = float(progress) / float(total)
    if progress >= 1.:
      progress, status = 1, "\r\n"
    block = int(round(barLength * progress))
    text = "\r[{}] {:.0f}% {}".format(
        "#" * block + "-" * (barLength - block), round(progress * 100, 0),
    status)
    sys.stdout.write(text)
    sys.stdout.flush()


    runs = 250
        for run_num in range(runs):
        time.sleep(.1)
        updt(runs, run_num + 1)
        time.sleep(1)

推荐阅读