其他分享
首页 > 其他分享> > 剑指加载小尾部

剑指加载小尾部

作者:互联网

核心思路

  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

  

标签:load,__,end,尾部,ui,print,prompt,加载
来源: https://www.cnblogs.com/2bjiujiu/p/13759065.html