剑指加载小尾部

核心思路

  1. 去掉print输出函数后面的默认换行为需要的符号
  2. 通过for循环重复输出
  4. 通过 退格符 \b 清空已经输出的字符 或 通过 \r 回到行首重新从当前输出
  5. 通过随机函数random和时间函数sleep控制输出间隔

# --\|/ 加载页面
import time
import random


def load_ui():
    ui_char = ["--", "\\", "|", "/"]
    while True:
        for item in ui_char:
            print(item, end="")
            time.sleep(.4)
            print("\r", end="")


# ... 加载页面=
def load_ui_dot():
    prompt = "."
    while True:
        for item in range(3):
            print(prompt, end="")
            time.sleep(.8)
            if item == 2:
                print("\r", end="")


def load_ui_process():
    # 进度的提示符
    prompt = "#"
    head_show = "{}% "
    for i in range(10+1):
        print(head_show.format(i * 10) + ''.center(i, prompt), end="")
        time.sleep(random.random())
        print("\r", end="")


if __name__ == "__main__":
    load_ui()
    pass

  

posted @ 2020-10-01 20:54  梦_鱼  阅读(114)  评论(0编辑  收藏  举报